用Kotlin在Spring Boot中读取超大StackOverflow XML
【摘要】 编程语言:kotlin框架:Spring Boot测试文件大小:73G private fun loadXML() { val factory = SAXParserFactory.newInstance() try { val parser = factory.newSAXParser() val file = F...
编程语言:
kotlin
框架:
Spring Boot
测试文件大小:
73G
private fun loadXML() {
val factory = SAXParserFactory.newInstance()
try {
val parser = factory.newSAXParser()
val file = File("D:/data/stackoverflow/stackoverflow.com-Posts/PostsCopy.xml")
val rowHandler = RowHandler()
parser.parse(file, rowHandler)
} catch (e: ParserConfigurationException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
} catch (e: SAXException) {
e.printStackTrace()
}
}
import com.ding.xml.models.Row
import org.xml.sax.Attributes
import org.xml.sax.SAXException
import org.xml.sax.helpers.DefaultHandler
class RowHandler : DefaultHandler() {
@Throws(SAXException::class)
override fun startElement(uri: String?, localName: String?, qName: String?, attributes: Attributes) {
for (i in 0 until attributes.length) {
println(attributes.getQName(i) + "=" +
attributes.getValue(i))
}
}
@Throws(SAXException::class)
override fun characters(ch: CharArray?, start: Int, length: Int) {
//Unchanged from your implementation
}
@Throws(SAXException::class)
override fun endElement(uri: String?, localName: String?, qName: String?) {
// Elide code not needing change
}
}
运行效果:
LastEditDate=2013-10-11T00:49:16.817 LastActivityDate=2013-10-11T00:49:16.817 CommentCount=1 Id=3013 PostTypeId=2 ParentId=2709 CreationDate=2008-08-06T01:58:18.353 Score=1 Body=
You seem to have answered your own question there Nathan ;-)
"GetLastInputInfo" is the way to go.
One trick is that if your application is running on the desktop, and the user connects to a virtual machine, then GetLastInputInfo will report no activity (since there is no activity on the host machine).
This can be different to the behaviour you want, depending on how you wish to apply the user input.
OwnerUserId=49 LastActivityDate=2008-08-06T01:58:18.353 CommentCount=1 Id=3017 PostTypeId=1 AcceptedAnswerId=3029 CreationDate=2008-08-06T02:15:14.123 Score=219 ViewCount=416897 Body=
By "generate", I mean auto-generation of the code necessary for a particular selected (set of) variable(s).
But any more explicit explication or comment on good practice is welcome.
OwnerUserId=391 LastEditorUserId=63550 LastEditorDisplayName=EnderMB LastEditDate=2019-12-09T17:56:00.820 LastActivityDate=2019-12-25T23:38:43.047 Title=How can we generate getters and setters in Visual Studio? Tags=<c#><visual-studio><setter><getter> AnswerCount=16 CommentCount=0 FavoriteCount=47 Id=3019 PostTypeId=2 ParentId=3017 CreationDate=2008-08-06T02:24:29.130 Score=0 Body=
I don't have Visual Studio installed on my machine anymore (and I'm using Linux), but I do remember that there was an wizard hidden somewhere inside one of the menus that gave access to a class builder.
With this wizard, you could define all your classes' details, including methods and attributes. If I remember well, there was an option through which you could ask Visual Studio to create the setters and getters automatically for you.
I know it's quite vague, but check it out and you might find it.
OwnerUserId=431 LastEditorUserId=63550 LastEditDate=2019-12-09T18:05:15.310 LastActivityDate=2019-12-09T18:05:15.310 CommentCount=0 Id=3020 PostTypeId=2 ParentId=1683 CreationDate=2008-08-06T02:26:35.333
Score=11
LastEditDate=2013-10-11T00:49:16.817
LastActivityDate=2013-10-11T00:49:16.817
CommentCount=1
Id=3013
PostTypeId=2
ParentId=2709
CreationDate=2008-08-06T01:58:18.353
Score=1
Body=
You seem to have answered your own question there Nathan ;-)
"GetLastInputInfo" is the way to go.
One trick is that if your application is running on the desktop, and the user connects to a virtual machine, then GetLastInputInfo will report no activity (since there is no activity on the host machine).
This can be different to the behaviour you want, depending on how you wish to apply the user input.
OwnerUserId=49
LastActivityDate=2008-08-06T01:58:18.353
CommentCount=1
Id=3017
PostTypeId=1
AcceptedAnswerId=3029
CreationDate=2008-08-06T02:15:14.123
Score=219
ViewCount=416897
Body=
By "generate", I mean auto-generation of the code necessary for a particular selected (set of) variable(s).
But any more explicit explication or comment on good practice is welcome.
OwnerUserId=391
LastEditorUserId=63550
LastEditorDisplayName=EnderMB
LastEditDate=2019-12-09T17:56:00.820
LastActivityDate=2019-12-25T23:38:43.047
Title=How can we generate getters and setters in Visual Studio?
Tags=<c#><visual-studio><setter><getter>
AnswerCount=16
CommentCount=0
FavoriteCount=47
Id=3019
PostTypeId=2
ParentId=3017
CreationDate=2008-08-06T02:24:29.130
Score=0
Body=
I don't have Visual Studio installed on my machine anymore (and I'm using Linux), but I do remember that there was an wizard hidden somewhere inside one of the menus that gave access to a class builder.
With this wizard, you could define all your classes' details, including methods and attributes. If I remember well, there was an option through which you could ask Visual Studio to create the setters and getters automatically for you.
I know it's quite vague, but check it out and you might find it.
OwnerUserId=431
LastEditorUserId=63550
LastEditDate=2019-12-09T18:05:15.310
LastActivityDate=2019-12-09T18:05:15.310
CommentCount=0
Id=3020
PostTypeId=2
ParentId=1683
CreationDate=2008-08-06T02:26:35.333
Score=11
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)