--- old/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/staxex/Base64Data.java 2013-04-04 15:28:20.724613912 +0200 +++ new/src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/staxex/Base64Data.java 2013-04-04 15:28:20.660613911 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,11 +36,13 @@ import java.io.OutputStream; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import java.util.logging.Level; +import java.util.logging.Logger; // for testing method //import com.sun.xml.internal.stream.writers.XMLStreamWriterImpl; //import java.io.FileNotFoundException; -//import java.io.StringWriter; +//import java.io.FileWriter; //import javax.activation.FileDataSource; /** @@ -59,8 +61,8 @@ // (note that having both is allowed) private DataHandler dataHandler; - private byte[] data; + /** * Length of the valid data in {@link #data}. */ @@ -84,6 +86,8 @@ public Base64Data() { } + private static final Logger logger = Logger.getLogger(Base64Data.class.getName()); + /** * Clone constructor * @param that needs to be cloned @@ -429,15 +433,30 @@ Base64Encoder.print(data, 0, dataLen, buf, start); } + private static final int CHUNK_SIZE; + static { + int bufSize = 1024; + try { + String bufSizeStr = getProperty("com.sun.xml.internal.org.jvnet.staxex.Base64DataStreamWriteBufferSize"); + if (bufSizeStr != null) { + bufSize = Integer.parseInt(bufSizeStr); + } + } catch (Exception e) { + logger.log(Level.INFO, "Error reading com.sun.xml.internal.org.jvnet.staxex.Base64DataStreamWriteBufferSize property", e); + } + CHUNK_SIZE = bufSize; + } + public void writeTo(XMLStreamWriter output) throws IOException, XMLStreamException { if (data==null) { try { InputStream is = dataHandler.getDataSource().getInputStream(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); // dev-null stream Base64EncoderStream encWriter = new Base64EncoderStream(output, outStream); - int b = -1; - while ((b = is.read()) != -1) { - encWriter.write(b); + int b; + byte[] buffer = new byte[CHUNK_SIZE]; + while ((b = is.read(buffer)) != -1) { + encWriter.write(buffer, 0, b); } outStream.close(); encWriter.close(); @@ -457,17 +476,33 @@ return new Base64Data(this); } + static String getProperty(final String propName) { + if (System.getSecurityManager() == null) { + return System.getProperty(propName); + } else { + return (String) java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public java.lang.Object run() { + return System.getProperty(propName); + } + }); + } + } + // public static void main(String[] args) throws FileNotFoundException, IOException, XMLStreamException { // Base64Data data = new Base64Data(); // -// data.set(new DataHandler(new FileDataSource(new File("/home/snajper/Desktop/a.txt")))); +// File f = new File("/Users/snajper/work/builds/weblogic/wls1211_dev.zip"); +// FileDataSource fds = new FileDataSource(f); +// DataHandler dh = new DataHandler(fds); +// data.set(dh); // -// StringWriter sw = new StringWriter(); -// XMLStreamWriterImpl wi = new XMLStreamWriterImpl(sw, null); +// FileWriter fw = new FileWriter(new File("/Users/snajper/Desktop/b.txt")); +// XMLStreamWriterImpl wi = new XMLStreamWriterImpl(fw, null); // // data.writeTo(wi); -// wi.flush();sw.flush(); -// System.out.println("SW: " + sw.toString()); +// wi.flush();fw.flush(); +// //System.out.println("SW: " + sw.toString()); // // }