由于ByteArrayInputStream限制为2GB,是否有任何替代解决方案允许我将2.3GB(可能更大)文件的全部内容存储到一个由Stax2读取的InputStream中?
当前代码:
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(in); //ByteArrayInputStream???? try { SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); Schema schema = factory.newSchema(new StreamSource(schemaInputStream)); Validator validator = schema.newValidator(); validator.validate(new StAXSource(xmlStreamReader)); } finally { xmlStreamReader.close(); }
对于性能调优,变量in不得来自磁盘.我有很多RAM.
解决方法
使用NIO将文件读入一个巨大的ByteBuffer,然后创建一个读取ByteBuffer的流类.在开源中有几个这样的浮动.