==================================================================== */
package org.apache.poi.ooxml.dev;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import java.io.*;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
* Reads a zipped OOXML file and produces a copy with the included
* pretty-printed XML files.
*
- * This is useful for comparing OOXML files produced by different tools as the often
+ * This is useful for comparing OOXML files produced by different tools as they often
* use different formatting of the XML.
*/
public class OOXMLPrettyPrint {
pretty(document, out, 2);
} else {
System.out.println("Not pretty-printing non-XML file " + name);
- IOUtils.copy(file.getInputStream(entry), out);
+ try (InputStream in = file.getInputStream(entry)) {
+ IOUtils.copy(in, out);
+ }
}
} catch (Exception e) {
throw new IOException("While handling entry " + name, e);
dest.addRelationship(part.getPartName(), rel.getTargetMode(), rel.getRelationshipType());
part_tgt = dest.createPart(part.getPartName(), part.getContentType());
- try (OutputStream out = part_tgt.getOutputStream()) {
- IOUtils.copy(part.getInputStream(), out);
+ try (
+ InputStream in = part.getInputStream();
+ OutputStream out = part_tgt.getOutputStream()
+ ) {
+ IOUtils.copy(in, out);
}
if (part.hasRelationships()) {
}
@Override
- public boolean load(InputStream ios) throws InvalidFormatException {
+ public boolean load(InputStream is) throws InvalidFormatException {
try (OutputStream os = getOutputStreamImpl()) {
- IOUtils.copy(ios, os);
+ IOUtils.copy(is, os);
} catch(IOException e) {
throw new InvalidFormatException(e.getMessage(), e);
}
}
@Override
- public boolean load(InputStream ios) throws InvalidFormatException {
+ public boolean load(InputStream is) throws InvalidFormatException {
try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
// Grab the data
- IOUtils.copy(ios, baos);
+ IOUtils.copy(is, baos);
// Save it
data = baos.toByteArray();
} catch (IOException e) {
}
@Override
- public boolean load(InputStream ios) throws InvalidFormatException {
+ public boolean load(InputStream is) throws InvalidFormatException {
try (OutputStream os = getOutputStreamImpl()) {
- IOUtils.copy(ios, os);
+ IOUtils.copy(is, os);
} catch(IOException e) {
throw new InvalidFormatException(e.getMessage(), e);
}