开发者

Java Applet slow when using ByteArrayStream

开发者 https://www.devze.com 2023-03-14 23:11 出处:网络
I am transforming xml in an object of an own class called \"V6BasicCar\", the problem that I\'m having is that if I enable the Java cache (in Java control panel):

I am transforming xml in an object of an own class called "V6BasicCar", the problem that I'm having is that if I enable the Java cache (in Java control panel):

Java Applet slow when using ByteArrayStream

each transformation takes about 3-4 seconds, but if I disable caching, it takes just miliseconds. I don't know why this happens, my only guess is that Java is caching the ByteArrayStream per transformation and that makes it slower, but I haven't figured out how to deal with this problem. Is there any alternative to ByteArray Stream that would be faster?

Thanks.

The code:

{
..

ByteArrayOutputStream out = new ByteArrayOutputStream();

//1. transform xml    
transform(getSourceXml(_intype), out);

//2. convert to bean
XsdConverter<V6BasicCar> v6BasicCarXsdConverter = new XsdConverter<V6BasicCar>(V6BasicCar.class);     
    /* 
    "getObject()" takes about 2 secs 
    */
V6BasicCar newV6BasicCar = v6BasicCarXsdConverter.getObject(convert(out));

..
}


 protected InputStream getSourceXml(final CsvWrapperMiddle _csvV6Car) throws IOException, JAXBException
{
    ByteArrayOutputStream out = new ByteArrayOutputStream();   

        /* 
        "getXml" 开发者_JAVA技巧takes about 2 secs 
        */
    xsdConverter.getXml(_csvV6Car.getExternalBean(), out); 
    InputStream output = convert(out);   
    return output;
}

protected InputStream convert(ByteArrayOutputStream out)
{
    return new ByteArrayInputStream(out.toByteArray());
}


The problem was inside the XsdConverter, specifically in JAXB. Setting "com.sun.xml.bind.v2.runtime.JAXBContextImpl.fastBoot" to true fixed the problem

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号