From 0d6a0f3522debd7edb5903ce8b39225f50b9675f Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Nov 2025 09:45:16 +0300 Subject: [PATCH 1/6] XGC-148: use try-with-resources instead of IOUtils.closeQuietly Fixes https://issues.apache.org/jira/browse/XGC-148 --- .../image/writer/ImageWriterExample1.java | 8 ++----- .../image/writer/ImageWriterExample2.java | 7 ++---- examples/java/java2d/ps/EPSColorsExample.java | 9 ++------ examples/java/java2d/ps/EPSExample1.java | 8 ++----- .../java/java2d/ps/TilingPatternExample.java | 9 ++------ examples/java/ps/DSCProcessingExample1.java | 22 ++++++------------- .../org/apache/xmlgraphics/fonts/Glyphs.java | 15 +++++-------- .../impl/AbstractImageSessionContext.java | 16 +++++++++++--- .../image/loader/impl/ImageRawStream.java | 14 +++++++----- .../pipeline/ImageProviderPipeline.java | 5 +---- .../image/writer/ImageWriterUtil.java | 8 ++----- .../apache/xmlgraphics/io/XmlSourceUtil.java | 20 ++++++++++++----- .../apache/xmlgraphics/ps/PSGenerator.java | 5 +---- .../org/apache/xmlgraphics/util/Service.java | 14 +++++------- .../xmlgraphics/xmp/XMPPacketParser.java | 7 +----- .../codec/png/CodecResourcesTestCase.java | 12 ++++------ .../image/loader/ImageLoaderTestCase.java | 12 ++-------- .../image/writer/ResolutionTestCase.java | 8 ++----- .../NamedColorProfileParserTestCase.java | 9 ++------ .../xmlgraphics/ps/dsc/ListenerTestCase.java | 12 ++-------- 20 files changed, 81 insertions(+), 139 deletions(-) diff --git a/examples/java/image/writer/ImageWriterExample1.java b/examples/java/image/writer/ImageWriterExample1.java index c70b0294..ad921375 100644 --- a/examples/java/image/writer/ImageWriterExample1.java +++ b/examples/java/image/writer/ImageWriterExample1.java @@ -29,7 +29,6 @@ import java.io.OutputStream; import java.text.AttributedString; -import org.apache.commons.io.IOUtils; import org.apache.xmlgraphics.image.writer.ImageWriter; import org.apache.xmlgraphics.image.writer.ImageWriterParams; import org.apache.xmlgraphics.image.writer.ImageWriterRegistry; @@ -106,9 +105,8 @@ public void generateBitmapUsingJava2D(File outputFile, String format) //Paint something paintSome(g2d, 1); - OutputStream out = new java.io.FileOutputStream(outputFile); - out = new java.io.BufferedOutputStream(out); - try { + try (OutputStream fout = new java.io.FileOutputStream(outputFile); + OutputStream out = new java.io.BufferedOutputStream(fout)) { ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(format); ImageWriterParams params = new ImageWriterParams(); @@ -116,8 +114,6 @@ public void generateBitmapUsingJava2D(File outputFile, String format) params.setResolution(72); writer.writeImage(bimg, out, params); - } finally { - IOUtils.closeQuietly(out); } } diff --git a/examples/java/image/writer/ImageWriterExample2.java b/examples/java/image/writer/ImageWriterExample2.java index d0b1ef32..ca401187 100644 --- a/examples/java/image/writer/ImageWriterExample2.java +++ b/examples/java/image/writer/ImageWriterExample2.java @@ -67,9 +67,8 @@ public void generateBitmapUsingJava2D(File outputFile, String format) //String compression = "CCITT T.6"; String compression = "PackBits"; - OutputStream out = new java.io.FileOutputStream(outputFile); - out = new java.io.BufferedOutputStream(out); - try { + try (OutputStream fout = new java.io.FileOutputStream(outputFile); + OutputStream out = new java.io.BufferedOutputStream(fout)) { ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(format); ImageWriterParams params = new ImageWriterParams(); @@ -86,8 +85,6 @@ public void generateBitmapUsingJava2D(File outputFile, String format) + format); } - } finally { - IOUtils.closeQuietly(out); } } diff --git a/examples/java/java2d/ps/EPSColorsExample.java b/examples/java/java2d/ps/EPSColorsExample.java index 95c7d69b..f49947e5 100644 --- a/examples/java/java2d/ps/EPSColorsExample.java +++ b/examples/java/java2d/ps/EPSColorsExample.java @@ -25,8 +25,6 @@ import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.java2d.color.CIELabColorSpace; import org.apache.xmlgraphics.java2d.color.ColorSpaces; import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace; @@ -45,9 +43,8 @@ public class EPSColorsExample { * @throws IOException In case of an I/O error */ public static void generateEPSusingJava2D(File outputFile) throws IOException { - OutputStream out = new java.io.FileOutputStream(outputFile); - out = new java.io.BufferedOutputStream(out); - try { + try (OutputStream fout = new java.io.FileOutputStream(outputFile); + OutputStream out = new java.io.BufferedOutputStream(fout)) { //Instantiate the EPSDocumentGraphics2D instance EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); @@ -96,8 +93,6 @@ public static void generateEPSusingJava2D(File outputFile) throws IOException { //Cleanup g2d.finish(); - } finally { - IOUtils.closeQuietly(out); } } diff --git a/examples/java/java2d/ps/EPSExample1.java b/examples/java/java2d/ps/EPSExample1.java index dd112796..8adfbbf0 100644 --- a/examples/java/java2d/ps/EPSExample1.java +++ b/examples/java/java2d/ps/EPSExample1.java @@ -26,7 +26,6 @@ import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D; /** @@ -42,9 +41,8 @@ public class EPSExample1 { * @throws IOException In case of an I/O error */ public static void generateEPSusingJava2D(File outputFile) throws IOException { - OutputStream out = new java.io.FileOutputStream(outputFile); - out = new java.io.BufferedOutputStream(out); - try { + try (OutputStream fout = new java.io.FileOutputStream(outputFile); + OutputStream out = new java.io.BufferedOutputStream(fout)) { //Instantiate the EPSDocumentGraphics2D instance EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); @@ -78,8 +76,6 @@ public static void generateEPSusingJava2D(File outputFile) throws IOException { //Cleanup g2d.finish(); - } finally { - IOUtils.closeQuietly(out); } } diff --git a/examples/java/java2d/ps/TilingPatternExample.java b/examples/java/java2d/ps/TilingPatternExample.java index be307837..a5da198e 100644 --- a/examples/java/java2d/ps/TilingPatternExample.java +++ b/examples/java/java2d/ps/TilingPatternExample.java @@ -33,8 +33,6 @@ import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.image.writer.ImageWriterUtil; import org.apache.xmlgraphics.java2d.ps.PSDocumentGraphics2D; @@ -71,9 +69,8 @@ public TilingPatternExample() { * @throws IOException In case of an I/O error */ public void generatePSusingJava2D(File outputFile) throws IOException { - OutputStream out = new java.io.FileOutputStream(outputFile); - out = new java.io.BufferedOutputStream(out); - try { + try (OutputStream fout = new java.io.FileOutputStream(outputFile); + OutputStream out = new java.io.BufferedOutputStream(out)) { //Instantiate the PSDocumentGraphics2D instance PSDocumentGraphics2D g2d = new PSDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); @@ -91,8 +88,6 @@ public void generatePSusingJava2D(File outputFile) throws IOException { //Cleanup g2d.finish(); - } finally { - IOUtils.closeQuietly(out); } } diff --git a/examples/java/ps/DSCProcessingExample1.java b/examples/java/ps/DSCProcessingExample1.java index 60cc0bc9..19361487 100644 --- a/examples/java/ps/DSCProcessingExample1.java +++ b/examples/java/ps/DSCProcessingExample1.java @@ -24,7 +24,6 @@ import java.io.OutputStream; import java.io.InputStream; -import org.apache.commons.io.IOUtils; import org.apache.xmlgraphics.ps.dsc.DSCException; import org.apache.xmlgraphics.ps.dsc.tools.PageExtractor; @@ -44,20 +43,13 @@ public class DSCProcessingExample1 { * @throws IOException In case of an I/O error */ public void extractPages(File srcFile, File tgtFile, int from, int to) throws IOException { - InputStream in = new java.io.FileInputStream(srcFile); - in = new java.io.BufferedInputStream(in); - try { - OutputStream out = new java.io.FileOutputStream(tgtFile); - out = new java.io.BufferedOutputStream(out); - try { - PageExtractor.extractPages(in, out, from, to); - } catch (DSCException e) { - throw new RuntimeException(e.getMessage()); - } finally { - IOUtils.closeQuietly(out); - } - } finally { - IOUtils.closeQuietly(in); + try (InputStream fin = new java.io.FileInputStream(srcFile); + InputStream in = new java.io.BufferedInputStream(fin); + OutputStream fout = new java.io.FileOutputStream(tgtFile); + OutputStream out = new java.io.BufferedOutputStream(fout)) { + PageExtractor.extractPages(in, out, from, to); + } catch (DSCException e) { + throw new RuntimeException(e.getMessage()); } } diff --git a/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java b/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java index b45abb5b..eadb21bc 100644 --- a/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java +++ b/src/main/java/org/apache/xmlgraphics/fonts/Glyphs.java @@ -29,8 +29,6 @@ import java.util.Map; import java.util.StringTokenizer; -import org.apache.commons.io.IOUtils; - /** * This class provides a number of constants for glyph management. */ @@ -651,12 +649,11 @@ private static void addAlternatives(Map map, String[] alternatives) { private static String[] loadGlyphList(String filename, Map charNameToUnicodeMap) { List lines = new java.util.ArrayList(); - InputStream in = Glyphs.class.getResourceAsStream(filename); - if (in == null) { - throw new RuntimeException("Cannot load " + filename - + ". The Glyphs class cannot properly be initialized!"); - } - try { + try (InputStream in = Glyphs.class.getResourceAsStream(filename)) { + if (in == null) { + throw new RuntimeException("Cannot load " + filename + + ". The Glyphs class cannot properly be initialized!"); + } BufferedReader reader = new BufferedReader(new InputStreamReader(in, "US-ASCII")); String line; try { @@ -674,8 +671,6 @@ private static String[] loadGlyphList(String filename, Map charNameToUnicodeMap) } catch (IOException ioe) { throw new RuntimeException("I/O error while loading " + filename + ". The Glyphs class cannot properly be initialized!"); - } finally { - IOUtils.closeQuietly(in); } String[] arr = new String[lines.size() * 2]; int pos = 0; diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java b/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java index 994cc9b7..03cc3b24 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java @@ -40,7 +40,6 @@ import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamSource; -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -133,7 +132,14 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl try { return method.invoke(iin, args); } finally { - IOUtils.closeQuietly(this.in); + InputStream in = this.in; + if (in != null) { + try { + in.close(); + } catch (IOException ignore) { + // ignore + } + } this.in = null; } } else { @@ -330,7 +336,11 @@ public Source createSource(Source source, String uri) { if (directFileAccess) { //Close as the file is reopened in a more optimal way - IOUtils.closeQuietly(in); + try { + in.close(); + } catch (IOException ignore) { + // ignore + } try { // We let the OS' file system cache do the caching for us // --> lower Java memory consumption, probably no speed loss diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java index 23ec0cc0..e82391b0 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java @@ -111,11 +111,8 @@ public InputStream createInputStream() { * @throws IOException if an I/O error occurs */ public void writeTo(OutputStream out) throws IOException { - InputStream in = createInputStream(); - try { + try (InputStream in = createInputStream()) { IOUtils.copy(in, out); - } finally { - IOUtils.closeQuietly(in); } } @@ -166,7 +163,14 @@ public synchronized InputStream createInputStream() { } public synchronized void close() { - IOUtils.closeQuietly(this.in); + InputStream in = this.in; + if (in != null) { + try { + in.close(); + } catch (IOException ignore) { + // ignore + } + } this.in = null; } diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java b/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java index 0399e780..44cf6722 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java @@ -225,11 +225,8 @@ protected Image forceCaching(Image img) throws IOException { //Read the whole stream and hold it in memory so the image can be cached ByteArrayOutputStream baout = new ByteArrayOutputStream(); - InputStream in = raw.createInputStream(); - try { + try (InputStream in = raw.createInputStream()) { IOUtils.copy(in, baout); - } finally { - IOUtils.closeQuietly(in); } final byte[] data = baout.toByteArray(); raw.setInputStreamFactory(new ImageRawStream.ByteArrayStreamFactory(data)); diff --git a/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java b/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java index c28264d6..ca3422e8 100644 --- a/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java +++ b/src/main/java/org/apache/xmlgraphics/image/writer/ImageWriterUtil.java @@ -23,8 +23,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; - -import org.apache.commons.io.IOUtils; +import java.nio.file.Files; /** * Convenience methods around ImageWriter for the most important tasks. @@ -68,14 +67,11 @@ public static void saveAsPNG(RenderedImage bitmap, int resolution, File outputFi public static void saveAsFile(RenderedImage bitmap, int resolution, File outputFile, String mime) throws IOException { - OutputStream out = new java.io.FileOutputStream(outputFile); - try { + try (OutputStream out = Files.newOutputStream(outputFile.toPath())) { ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(mime); ImageWriterParams params = new ImageWriterParams(); params.setResolution(resolution); writer.writeImage(bitmap, out, params); - } finally { - IOUtils.closeQuietly(out); } } diff --git a/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java b/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java index bccc02ae..691bda35 100644 --- a/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java +++ b/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java @@ -19,6 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -32,8 +33,6 @@ import org.xml.sax.InputSource; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.image.loader.ImageSource; import org.apache.xmlgraphics.image.loader.util.ImageInputStreamAdapter; import org.apache.xmlgraphics.image.loader.util.ImageUtil; @@ -137,7 +136,7 @@ public static void removeStreams(Source src) { public static void closeQuietly(Source src) { if (src instanceof StreamSource) { StreamSource streamSource = (StreamSource) src; - IOUtils.closeQuietly(streamSource.getReader()); + closeQuietly(streamSource.getReader()); } else if (src instanceof ImageSource) { if (ImageUtil.getImageInputStream(src) != null) { try { @@ -149,13 +148,24 @@ public static void closeQuietly(Source src) { } else if (src instanceof SAXSource) { InputSource is = ((SAXSource) src).getInputSource(); if (is != null) { - IOUtils.closeQuietly(is.getByteStream()); - IOUtils.closeQuietly(is.getCharacterStream()); + closeQuietly(is.getByteStream()); + closeQuietly(is.getCharacterStream()); } } removeStreams(src); } + private static void closeQuietly(Closeable in) { + if (in == null) { + return; + } + try { + in.close(); + } catch (IOException ignore) { + // ignore + } + } + /** * Indicates whether the Source object has an InputStream instance. * @param src the Source object diff --git a/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java b/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java index 07c2b79b..58f1de9f 100644 --- a/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java +++ b/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java @@ -841,11 +841,8 @@ public boolean embedIdentityH() throws IOException { } else { resTracker.registerNeededResource(getProcsetCIDInitResource()); writeDSCComment(DSCConstants.BEGIN_DOCUMENT, IDENTITY_H); - InputStream cmap = PSGenerator.class.getResourceAsStream(IDENTITY_H); - try { + try (InputStream cmap = PSGenerator.class.getResourceAsStream(IDENTITY_H)) { IOUtils.copyLarge(cmap, out); - } finally { - IOUtils.closeQuietly(cmap); } writeDSCComment(DSCConstants.END_DOCUMENT); resTracker.registerSuppliedResource(getIdentityHCMapResource()); diff --git a/src/main/java/org/apache/xmlgraphics/util/Service.java b/src/main/java/org/apache/xmlgraphics/util/Service.java index 4e8b4f7e..198246e1 100644 --- a/src/main/java/org/apache/xmlgraphics/util/Service.java +++ b/src/main/java/org/apache/xmlgraphics/util/Service.java @@ -19,6 +19,7 @@ package org.apache.xmlgraphics.util; +import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -31,8 +32,6 @@ import java.util.List; import java.util.Map; -import org.apache.commons.io.IOUtils; - /** * This class handles looking up service providers on the class path. * It implements the system described in: @@ -161,10 +160,10 @@ private static List getProviderNames(Class cls, ClassLoader cl) { try { URL u = e.nextElement(); - InputStream is = u.openStream(); - Reader r = new InputStreamReader(is, StandardCharsets.UTF_8); - BufferedReader br = new BufferedReader(r); - try { + try (InputStream is = u.openStream(); + BufferedInputStream bis = new BufferedInputStream(is); + Reader r = new InputStreamReader(bis, StandardCharsets.UTF_8); + BufferedReader br = new BufferedReader(r)) { for (String line = br.readLine(); line != null; line = br.readLine()) { // First strip any comment... int idx = line.indexOf('#'); @@ -179,9 +178,6 @@ private static List getProviderNames(Class cls, ClassLoader cl) { l.add(line); } } - } finally { - IOUtils.closeQuietly(br); - IOUtils.closeQuietly(is); } } catch (Exception ex) { // Just try the next file... diff --git a/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java b/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java index 8f7eb124..5de696b5 100644 --- a/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java +++ b/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java @@ -28,7 +28,6 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.stream.StreamSource; -import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; /** @@ -79,20 +78,16 @@ public static Metadata parse(InputStream in) throws IOException, TransformerExce if (!skipAfter(in, PACKET_HEADER_END)) { throw new IOException("Invalid XMP packet header!"); } - ByteArrayOutputStream baout = null; Metadata metadata; - try { + try (ByteArrayOutputStream baout = new ByteArrayOutputStream()) { //TODO think about not buffering this but for example, parse in another thread //ex. using PipedInput/OutputStream - baout = new ByteArrayOutputStream(); //TODO Do with TeeInputStream when Commons IO 1.4 is available if (!skipAfter(in, PACKET_TRAILER, baout)) { throw new IOException("XMP packet not properly terminated!"); } metadata = XMPParser.parseXMP( new StreamSource(new ByteArrayInputStream(baout.toByteArray()))); - } finally { - IOUtils.closeQuietly(baout); } return metadata; } diff --git a/src/test/java/org/apache/xmlgraphics/image/codec/png/CodecResourcesTestCase.java b/src/test/java/org/apache/xmlgraphics/image/codec/png/CodecResourcesTestCase.java index e58cd788..67a70584 100644 --- a/src/test/java/org/apache/xmlgraphics/image/codec/png/CodecResourcesTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/image/codec/png/CodecResourcesTestCase.java @@ -20,13 +20,13 @@ package org.apache.xmlgraphics.image.codec.png; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; import org.junit.Test; import static org.junit.Assert.fail; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.image.codec.util.MemoryCacheSeekableStream; import org.apache.xmlgraphics.image.codec.util.SeekableStream; @@ -38,9 +38,8 @@ public class CodecResourcesTestCase { @Test public void testResources() throws Exception { - InputStream in = new java.io.FileInputStream("test/images/barcode.eps"); - SeekableStream seekStream = new MemoryCacheSeekableStream(in); - try { + try (InputStream in = Files.newInputStream(Paths.get("test/images/barcode.eps")); + SeekableStream seekStream = new MemoryCacheSeekableStream(in)) { new PNGImage(seekStream, null); fail("Exception expected"); } catch (RuntimeException re) { @@ -51,9 +50,6 @@ public void testResources() throws Exception { } else if (msg.toLowerCase().indexOf("magic") < 0) { fail("Message not as expected! Message is: " + msg); } - } finally { - IOUtils.closeQuietly(seekStream); - IOUtils.closeQuietly(in); } } } diff --git a/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java b/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java index df46ce46..f9dd7932 100644 --- a/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/image/loader/ImageLoaderTestCase.java @@ -38,8 +38,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.image.loader.impl.ImageLoaderPNG; import org.apache.xmlgraphics.image.loader.impl.ImageLoaderRawPNG; import org.apache.xmlgraphics.image.loader.impl.ImageRawStream; @@ -121,8 +119,7 @@ public void testEPSASCII() throws Exception { assertNotNull("Image must not be null", img); assertEquals(ImageFlavor.RAW_EPS, img.getFlavor()); ImageRawStream imgEPS = (ImageRawStream) img; - InputStream in = imgEPS.createInputStream(); - try { + try (InputStream in = imgEPS.createInputStream()) { assertNotNull(in); Reader reader = new InputStreamReader(in, "US-ASCII"); char[] c = new char[4]; @@ -130,8 +127,6 @@ public void testEPSASCII() throws Exception { if (!("%!PS".equals(new String(c)))) { fail("EPS header expected"); } - } finally { - IOUtils.closeQuietly(in); } sessionContext.checkAllStreamsClosed(); @@ -151,8 +146,7 @@ public void testEPSBinary() throws Exception { assertNotNull("Image must not be null", img); assertEquals(ImageFlavor.RAW_EPS, img.getFlavor()); ImageRawStream imgEPS = (ImageRawStream) img; - InputStream in = imgEPS.createInputStream(); - try { + try (InputStream in = imgEPS.createInputStream()) { assertNotNull(in); Reader reader = new InputStreamReader(in, "US-ASCII"); char[] c = new char[4]; @@ -160,8 +154,6 @@ public void testEPSBinary() throws Exception { if (!("%!PS".equals(new String(c)))) { fail("EPS header expected"); } - } finally { - IOUtils.closeQuietly(in); } sessionContext.checkAllStreamsClosed(); diff --git a/src/test/java/org/apache/xmlgraphics/image/writer/ResolutionTestCase.java b/src/test/java/org/apache/xmlgraphics/image/writer/ResolutionTestCase.java index e1707434..f1458203 100644 --- a/src/test/java/org/apache/xmlgraphics/image/writer/ResolutionTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/image/writer/ResolutionTestCase.java @@ -27,6 +27,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; import java.util.Iterator; import javax.imageio.ImageIO; @@ -43,8 +44,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.util.UnitConv; public class ResolutionTestCase { @@ -86,11 +85,8 @@ private void writeImage(ImageWriterParams params, File testFile, String mime) th BufferedImage img = createTestImage(); ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(mime); assertNotNull(writer); - OutputStream out = new java.io.FileOutputStream(testFile); - try { + try (OutputStream out = Files.newOutputStream(testFile.toPath())) { writer.writeImage(img, out, params); - } finally { - IOUtils.closeQuietly(out); } } diff --git a/src/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTestCase.java b/src/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTestCase.java index 9418a4ea..b4a41b8e 100644 --- a/src/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/java2d/color/profile/NamedColorProfileParserTestCase.java @@ -27,8 +27,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.java2d.color.NamedColorSpace; import org.apache.xmlgraphics.java2d.color.RenderingIntent; @@ -41,13 +39,10 @@ public class NamedColorProfileParserTestCase { @Test public void testParser() throws Exception { - InputStream in = getClass().getResourceAsStream(NCP_EXAMPLE_FILE); - assertNotNull(NCP_EXAMPLE_FILE + " is missing!", in); ICC_Profile iccProfile; - try { + try (InputStream in = getClass().getResourceAsStream(NCP_EXAMPLE_FILE)) { + assertNotNull(NCP_EXAMPLE_FILE + " is missing!", in); iccProfile = ICC_Profile.getInstance(in); - } finally { - IOUtils.closeQuietly(in); } NamedColorProfileParser parser = new NamedColorProfileParser(); NamedColorProfile ncp = parser.parseProfile(iccProfile); diff --git a/src/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java b/src/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java index 938504d8..7778a6b1 100644 --- a/src/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/ps/dsc/ListenerTestCase.java @@ -28,8 +28,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.ps.DSCConstants; import org.apache.xmlgraphics.ps.dsc.events.DSCComment; import org.apache.xmlgraphics.ps.dsc.events.DSCCommentLanguageLevel; @@ -46,8 +44,7 @@ public class ListenerTestCase { */ @Test public void testFilter() throws Exception { - InputStream in = getClass().getResourceAsStream("test1.txt"); - try { + try (InputStream in = getClass().getResourceAsStream("test1.txt")) { DSCParser parser = new DSCParser(in); parser.setFilter(new DSCFilter() { @@ -64,8 +61,6 @@ public boolean accept(DSCEvent event) { fail("Filter failed. Comment found."); } } - } finally { - IOUtils.closeQuietly(in); } } @@ -75,8 +70,7 @@ public boolean accept(DSCEvent event) { */ @Test public void testListeners() throws Exception { - InputStream in = getClass().getResourceAsStream("test1.txt"); - try { + try (InputStream in = getClass().getResourceAsStream("test1.txt")) { final Map results = new java.util.HashMap(); DSCParser parser = new DSCParser(in); @@ -122,8 +116,6 @@ public void processEvent(DSCEvent event, DSCParser parser) } assertEquals(12, count); assertEquals(1, results.get("level")); - } finally { - IOUtils.closeQuietly(in); } } From 64b4a6548fd8bab7ca87ab2f1b91b60f4908ae65 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Nov 2025 10:17:57 +0300 Subject: [PATCH 2/6] chore: replace IOUtils.toString with inline implementation --- .../util/uri/DataURIResolverTestCase.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java b/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java index 3ed0963a..9e27b81b 100644 --- a/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java @@ -20,6 +20,8 @@ package org.apache.xmlgraphics.util.uri; import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.Reader; import javax.xml.transform.Source; import javax.xml.transform.URIResolver; @@ -130,22 +132,32 @@ static final void actualURLHAndlingTest(URIResolver resolver) streamSource = (StreamSource) src; assertNull(streamSource.getInputStream()); assertNotNull(streamSource.getReader()); - String text = IOUtils.toString(streamSource.getReader()); + String text = toString(streamSource.getReader()); assertEquals("FOP", text); src = resolver.resolve("data:,A%20brief%20note", null); assertNotNull(src); streamSource = (StreamSource) src; - text = IOUtils.toString(streamSource.getReader()); + text = toString(streamSource.getReader()); assertEquals("A brief note", text); src = resolver.resolve("data:text/plain;charset=iso-8859-7,%be%f9%be", null); assertNotNull(src); streamSource = (StreamSource) src; - text = IOUtils.toString(streamSource.getReader()); + text = toString(streamSource.getReader()); assertEquals("\u038e\u03c9\u038e", text); } + private static String toString(Reader reader) throws IOException { + StringBuilder sb = new StringBuilder(); + char [] buf = new char[128]; + int n; + while ((n = reader.read(buf)) > 0) { + sb.append(buf, 0, n); + } + return sb.toString(); + } + /** * Test that the system Id is not null for the resulting stream objects * @throws Exception If an error occurs. From c97f0e11e4079a8537001cc4c2a66d2aff36f207 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Nov 2025 13:19:40 +0300 Subject: [PATCH 3/6] XGC-148: add xmlgraphics.util.io.IOUtils --- .../image/writer/ImageWriterExample2.java | 2 +- .../impl/AbstractImageSessionContext.java | 16 +-- .../image/loader/impl/ImageRawStream.java | 12 +- .../pipeline/ImageProviderPipeline.java | 2 +- .../apache/xmlgraphics/io/XmlSourceUtil.java | 19 +-- .../apache/xmlgraphics/ps/PSFontUtils.java | 2 +- .../apache/xmlgraphics/ps/PSGenerator.java | 5 +- .../apache/xmlgraphics/ps/PSImageUtils.java | 3 +- .../apache/xmlgraphics/util/io/IOUtils.java | 110 ++++++++++++++++++ .../xmlgraphics/util/uri/DataURLUtil.java | 11 +- .../codec/tiff/TIFFImageEncoderTestCase.java | 2 +- .../io/URIResolverAdapterTestCase.java | 11 +- .../xmlgraphics/io/XmlSourceUtilTestCase.java | 20 ++-- .../util/io/ASCII85InputStreamTestCase.java | 1 - .../xmlgraphics/util/io/Base64TestCase.java | 2 - .../util/uri/DataURIResolverTestCase.java | 19 +-- 16 files changed, 148 insertions(+), 89 deletions(-) create mode 100644 src/main/java/org/apache/xmlgraphics/util/io/IOUtils.java diff --git a/examples/java/image/writer/ImageWriterExample2.java b/examples/java/image/writer/ImageWriterExample2.java index ca401187..86bf69c2 100644 --- a/examples/java/image/writer/ImageWriterExample2.java +++ b/examples/java/image/writer/ImageWriterExample2.java @@ -26,11 +26,11 @@ import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; import org.apache.xmlgraphics.image.writer.ImageWriter; import org.apache.xmlgraphics.image.writer.ImageWriterParams; import org.apache.xmlgraphics.image.writer.ImageWriterRegistry; import org.apache.xmlgraphics.image.writer.MultiImageWriter; +import org.apache.xmlgraphics.util.io.IOUtils; public class ImageWriterExample2 extends ImageWriterExample1 { diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java b/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java index 03cc3b24..9bd7d728 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/impl/AbstractImageSessionContext.java @@ -48,6 +48,7 @@ import org.apache.xmlgraphics.image.loader.util.ImageUtil; import org.apache.xmlgraphics.image.loader.util.SoftMapCache; import org.apache.xmlgraphics.io.XmlSourceUtil; +import org.apache.xmlgraphics.util.io.IOUtils; /** * Abstract base class for classes implementing ImageSessionContext. This class provides all the @@ -132,14 +133,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl try { return method.invoke(iin, args); } finally { - InputStream in = this.in; - if (in != null) { - try { - in.close(); - } catch (IOException ignore) { - // ignore - } - } + IOUtils.closeQuietly(this.in); this.in = null; } } else { @@ -336,11 +330,7 @@ public Source createSource(Source source, String uri) { if (directFileAccess) { //Close as the file is reopened in a more optimal way - try { - in.close(); - } catch (IOException ignore) { - // ignore - } + IOUtils.closeQuietly(in); try { // We let the OS' file system cache do the caching for us // --> lower Java memory consumption, probably no speed loss diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java index e82391b0..675e7f10 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java @@ -24,11 +24,10 @@ import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.image.loader.ImageFlavor; import org.apache.xmlgraphics.image.loader.ImageInfo; import org.apache.xmlgraphics.image.loader.MimeEnabledImageFlavor; +import org.apache.xmlgraphics.util.io.IOUtils; /** * This class is an implementation of the Image interface exposing an InputStream for loading the @@ -163,14 +162,7 @@ public synchronized InputStream createInputStream() { } public synchronized void close() { - InputStream in = this.in; - if (in != null) { - try { - in.close(); - } catch (IOException ignore) { - // ignore - } - } + IOUtils.closeQuietly(this.in); this.in = null; } diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java b/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java index 44cf6722..83fef435 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,6 +40,7 @@ import org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry; import org.apache.xmlgraphics.image.loader.spi.ImageLoader; import org.apache.xmlgraphics.image.loader.util.Penalty; +import org.apache.xmlgraphics.util.io.IOUtils; /** * Represents a pipeline of ImageConverters with an ImageLoader at the beginning of the diff --git a/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java b/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java index 691bda35..893de1fc 100644 --- a/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java +++ b/src/main/java/org/apache/xmlgraphics/io/XmlSourceUtil.java @@ -19,7 +19,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -36,6 +35,7 @@ import org.apache.xmlgraphics.image.loader.ImageSource; import org.apache.xmlgraphics.image.loader.util.ImageInputStreamAdapter; import org.apache.xmlgraphics.image.loader.util.ImageUtil; +import org.apache.xmlgraphics.util.io.IOUtils; /** * A utility class for handling {@link Source} objects, more specficially the streams that back @@ -136,7 +136,7 @@ public static void removeStreams(Source src) { public static void closeQuietly(Source src) { if (src instanceof StreamSource) { StreamSource streamSource = (StreamSource) src; - closeQuietly(streamSource.getReader()); + IOUtils.closeQuietly(streamSource.getReader()); } else if (src instanceof ImageSource) { if (ImageUtil.getImageInputStream(src) != null) { try { @@ -148,24 +148,13 @@ public static void closeQuietly(Source src) { } else if (src instanceof SAXSource) { InputSource is = ((SAXSource) src).getInputSource(); if (is != null) { - closeQuietly(is.getByteStream()); - closeQuietly(is.getCharacterStream()); + IOUtils.closeQuietly(is.getByteStream()); + IOUtils.closeQuietly(is.getCharacterStream()); } } removeStreams(src); } - private static void closeQuietly(Closeable in) { - if (in == null) { - return; - } - try { - in.close(); - } catch (IOException ignore) { - // ignore - } - } - /** * Indicates whether the Source object has an InputStream instance. * @param src the Source object diff --git a/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java b/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java index 8200dc3d..7a198af8 100644 --- a/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java +++ b/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java @@ -24,10 +24,10 @@ import java.io.InputStream; import org.apache.commons.io.EndianUtils; -import org.apache.commons.io.IOUtils; import org.apache.xmlgraphics.fonts.Glyphs; import org.apache.xmlgraphics.util.io.ASCIIHexOutputStream; +import org.apache.xmlgraphics.util.io.IOUtils; import org.apache.xmlgraphics.util.io.SubInputStream; // CSOFF: HideUtilityClassConstructor diff --git a/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java b/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java index 58f1de9f..2b3b9f46 100644 --- a/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java +++ b/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java @@ -32,8 +32,6 @@ import javax.xml.transform.Source; -import org.apache.commons.io.IOUtils; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,6 +39,7 @@ import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives; import org.apache.xmlgraphics.ps.dsc.ResourceTracker; import org.apache.xmlgraphics.util.DoubleFormatUtil; +import org.apache.xmlgraphics.util.io.IOUtils; /** * This class is used to output PostScript code to an OutputStream. This class assumes that @@ -842,7 +841,7 @@ public boolean embedIdentityH() throws IOException { resTracker.registerNeededResource(getProcsetCIDInitResource()); writeDSCComment(DSCConstants.BEGIN_DOCUMENT, IDENTITY_H); try (InputStream cmap = PSGenerator.class.getResourceAsStream(IDENTITY_H)) { - IOUtils.copyLarge(cmap, out); + IOUtils.copy(cmap, out); } writeDSCComment(DSCConstants.END_DOCUMENT); resTracker.registerSuppliedResource(getIdentityHCMapResource()); diff --git a/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java b/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java index 32fd835b..7dd13834 100644 --- a/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java +++ b/src/main/java/org/apache/xmlgraphics/ps/PSImageUtils.java @@ -35,11 +35,10 @@ import java.io.OutputStream; import java.util.Arrays; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.util.io.ASCII85OutputStream; import org.apache.xmlgraphics.util.io.Finalizable; import org.apache.xmlgraphics.util.io.FlateEncodeOutputStream; +import org.apache.xmlgraphics.util.io.IOUtils; import org.apache.xmlgraphics.util.io.RunLengthEncodeOutputStream; // CSOFF: HideUtilityClassConstructor diff --git a/src/main/java/org/apache/xmlgraphics/util/io/IOUtils.java b/src/main/java/org/apache/xmlgraphics/util/io/IOUtils.java new file mode 100644 index 00000000..34056055 --- /dev/null +++ b/src/main/java/org/apache/xmlgraphics/util/io/IOUtils.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.xmlgraphics.util.io; + +import java.io.ByteArrayOutputStream; +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; + +/** + * Utility class providing convenience methods for I/O operations. + */ +public final class IOUtils { + private IOUtils() { + } + + /** + * Copies all bytes from the provided input stream to the given output stream. + * The method operates using a buffer and is useful for transferring data + * between streams without modifying the contents. + * + * @param input the {@code InputStream} to read data from, must not be {@code null} + * @param output the {@code OutputStream} to write data to, must not be {@code null} + * @return the total number of bytes copied + * @throws IOException if an I/O error occurs during reading or writing + */ + public static long copy(InputStream input, OutputStream output) throws IOException { + // TODO replace with input.transferTo(output) when Java 9+ is acceptable + byte[] buffer = new byte[4096]; + long count = 0; + int n; + while ((n = input.read(buffer)) != -1) { + output.write(buffer, 0, n); + count += n; + } + return count; + } + + /** + * Converts the contents of the provided InputStream into a byte array. + * This method reads all the data from the InputStream and writes it into + * a ByteArrayOutputStream, which is then converted to a byte array. + * + * @param input the InputStream to read data from, must not be {@code null} + * @return a byte array containing all the data read from the InputStream + * @throws IOException if an I/O error occurs while reading from the InputStream + */ + public static byte[] toByteArray(InputStream input) throws IOException { + // TODO replace with InputStream.readAllBytes when Java 9+ is acceptable + ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy(input, output); + return output.toByteArray(); + } + + /** + * Converts the contents of the provided Reader into a String. + * This method reads characters from the Reader into a buffer and then + * appends them to a StringBuilder, which is returned as a String. + * + * @param reader the Reader to read data from, must not be null + * @return a String containing all the characters read from the Reader + * @throws IOException if an I/O error occurs while reading from the Reader + */ + public static String toString(Reader reader) throws IOException { + StringBuilder sb = new StringBuilder(); + char [] buf = new char[128]; + int n; + while ((n = reader.read(buf)) > 0) { + sb.append(buf, 0, n); + } + return sb.toString(); + } + + /** + * Closes a {@code Closeable} object quietly, suppressing any exceptions + * that might occur during the close operation. If the provided {@code Closeable} + * is {@code null}, this method does nothing. + * + * @param closeable the {@code Closeable} object to close; may be {@code null}. + */ + public static void closeQuietly(Closeable closeable) { + if (closeable == null) { + return; + } + try { + closeable.close(); + } catch (Exception ignore) { + //Ignore + } + } +} diff --git a/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java b/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java index df6660fa..eb8854fa 100644 --- a/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java +++ b/src/main/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java @@ -24,10 +24,9 @@ import java.io.StringWriter; import java.io.Writer; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.util.WriterOutputStream; import org.apache.xmlgraphics.util.io.Base64EncodeStream; +import org.apache.xmlgraphics.util.io.IOUtils; /** * Utility classes for generating RFC 2397 data URLs. @@ -64,9 +63,9 @@ public static void writeDataURL(InputStream in, String mediatype, Writer writer) writer.write(mediatype); } writer.write(";base64,"); - Base64EncodeStream out = new Base64EncodeStream( - new WriterOutputStream(writer, "US-ASCII"), false); - IOUtils.copy(in, out); - out.close(); + try (Base64EncodeStream out = new Base64EncodeStream( + new WriterOutputStream(writer, "US-ASCII"), false)) { + IOUtils.copy(in, out); + } } } diff --git a/src/test/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoderTestCase.java b/src/test/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoderTestCase.java index 1603679d..44b3371b 100644 --- a/src/test/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoderTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/image/codec/tiff/TIFFImageEncoderTestCase.java @@ -28,7 +28,7 @@ import static org.junit.Assert.assertArrayEquals; -import org.apache.commons.io.IOUtils; +import org.apache.xmlgraphics.util.io.IOUtils; public class TIFFImageEncoderTestCase { diff --git a/src/test/java/org/apache/xmlgraphics/io/URIResolverAdapterTestCase.java b/src/test/java/org/apache/xmlgraphics/io/URIResolverAdapterTestCase.java index 57ae4f51..c145e15d 100644 --- a/src/test/java/org/apache/xmlgraphics/io/URIResolverAdapterTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/io/URIResolverAdapterTestCase.java @@ -19,10 +19,9 @@ import java.io.IOException; import java.io.InputStream; -import java.io.StringWriter; +import java.io.InputStreamReader; import java.net.URI; import java.net.URL; -import java.nio.charset.Charset; import javax.xml.transform.Source; import javax.xml.transform.TransformerException; @@ -34,9 +33,10 @@ import static org.junit.Assert.assertEquals; -import org.apache.commons.io.IOUtils; import org.apache.xml.resolver.tools.CatalogResolver; +import org.apache.xmlgraphics.util.io.IOUtils; + public class URIResolverAdapterTestCase { private final URI textFileURI = URI.create("test:catalog:resolver:testResource.txt"); @@ -66,9 +66,8 @@ public void testCatalogResolverInAdapter() throws IOException { } private void testInputStream(InputStream stream) throws IOException { - StringWriter writer = new StringWriter(); - IOUtils.copy(stream, writer, Charset.defaultCharset()); - assertEquals("This is a text file used to test the CatalogResolver\n", writer.toString()); + String result = IOUtils.toString(new InputStreamReader(stream)); + assertEquals("This is a text file used to test the CatalogResolver\n", result); } @Test diff --git a/src/test/java/org/apache/xmlgraphics/io/XmlSourceUtilTestCase.java b/src/test/java/org/apache/xmlgraphics/io/XmlSourceUtilTestCase.java index 1fe4b8d9..e67755b0 100644 --- a/src/test/java/org/apache/xmlgraphics/io/XmlSourceUtilTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/io/XmlSourceUtilTestCase.java @@ -19,9 +19,8 @@ import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Reader; -import java.io.StringWriter; -import java.nio.charset.Charset; import javax.imageio.stream.ImageInputStream; import javax.xml.parsers.DocumentBuilder; @@ -44,9 +43,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.apache.commons.io.IOUtils; - import org.apache.xmlgraphics.image.loader.ImageSource; +import org.apache.xmlgraphics.util.io.IOUtils; import static org.apache.xmlgraphics.io.XmlSourceUtil.closeQuietly; import static org.apache.xmlgraphics.io.XmlSourceUtil.getInputStream; @@ -63,7 +61,7 @@ public class XmlSourceUtilTestCase { private ImageSource imgSource; private ImageInputStream imgInStream; private DOMSource domSource; - private StringWriter writer; + private String result; private InputStream testStream; private Reader reader; @@ -91,8 +89,7 @@ public void setUp() throws IOException, ParserConfigurationException { DocumentBuilder db = dbf.newDocumentBuilder(); domSource = new DOMSource(db.newDocument().createElement("test")); InputStream inStream = XmlSourceUtil.getInputStream(domSource); - writer = new StringWriter(); - IOUtils.copy(inStream, writer, Charset.defaultCharset()); + result = IOUtils.toString(new InputStreamReader(inStream)); } @Test @@ -106,7 +103,7 @@ public void testGetInputStream() throws ParserConfigurationException, IOExceptio getInputStream(imgSource); verify(imgSource).getImageInputStream(); - assertEquals("", writer.toString()); + assertEquals("", result); // Test negative case Source src = mock(Source.class); @@ -124,7 +121,7 @@ public void testNeedInputStream() throws IOException, ParserConfigurationExcepti needInputStream(imgSource); verify(imgSource).getImageInputStream(); - assertEquals("", writer.toString()); + assertEquals("", result); } @Test(expected = IllegalArgumentException.class) @@ -145,9 +142,8 @@ public void testNeedInputStreamFailureCaseSAXSource() { public void testNeedInputStreamFailureCaseDOMSource() throws IOException { InputStream inStream = needInputStream(new DOMSource()); - StringWriter writer = new StringWriter(); - IOUtils.copy(inStream, writer, Charset.defaultCharset()); - assertEquals("", writer.toString()); + String result = IOUtils.toString(new InputStreamReader(inStream)); + assertEquals("", result); } @Test(expected = AssertionError.class) diff --git a/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java b/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java index 051ae1eb..4a921ca2 100644 --- a/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java @@ -28,7 +28,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.xmlgraphics.util.HexUtil; diff --git a/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java b/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java index 19a48608..69f5fa0a 100644 --- a/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java +++ b/src/test/java/org/apache/xmlgraphics/util/io/Base64TestCase.java @@ -33,8 +33,6 @@ import static org.junit.Assert.fail; -import org.apache.commons.io.IOUtils; - /** * This test validates that the Base64 encoder/decoders work properly. * diff --git a/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java b/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java index 9e27b81b..5deae8b2 100644 --- a/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/util/uri/DataURIResolverTestCase.java @@ -20,8 +20,6 @@ package org.apache.xmlgraphics.util.uri; import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.Reader; import javax.xml.transform.Source; import javax.xml.transform.URIResolver; @@ -34,7 +32,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import org.apache.commons.io.IOUtils; +import org.apache.xmlgraphics.util.io.IOUtils; /** * Test case for the RFC 2397 data URL/URI resolver. @@ -132,31 +130,22 @@ static final void actualURLHAndlingTest(URIResolver resolver) streamSource = (StreamSource) src; assertNull(streamSource.getInputStream()); assertNotNull(streamSource.getReader()); - String text = toString(streamSource.getReader()); + String text = IOUtils.toString(streamSource.getReader()); assertEquals("FOP", text); src = resolver.resolve("data:,A%20brief%20note", null); assertNotNull(src); streamSource = (StreamSource) src; - text = toString(streamSource.getReader()); + text = IOUtils.toString(streamSource.getReader()); assertEquals("A brief note", text); src = resolver.resolve("data:text/plain;charset=iso-8859-7,%be%f9%be", null); assertNotNull(src); streamSource = (StreamSource) src; - text = toString(streamSource.getReader()); + text = IOUtils.toString(streamSource.getReader()); assertEquals("\u038e\u03c9\u038e", text); } - private static String toString(Reader reader) throws IOException { - StringBuilder sb = new StringBuilder(); - char [] buf = new char[128]; - int n; - while ((n = reader.read(buf)) > 0) { - sb.append(buf, 0, n); - } - return sb.toString(); - } /** * Test that the system Id is not null for the resulting stream objects From 8a297e26c43e6623353dc50c6c1810156af87734 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Nov 2025 13:44:41 +0300 Subject: [PATCH 4/6] XGC-148: replace EndianUtils.readSwappedInteger with readLittleEndianInt --- .../org/apache/xmlgraphics/ps/PSFontUtils.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java b/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java index 7a198af8..cf86d04d 100644 --- a/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java +++ b/src/main/java/org/apache/xmlgraphics/ps/PSFontUtils.java @@ -23,8 +23,6 @@ import java.io.IOException; import java.io.InputStream; -import org.apache.commons.io.EndianUtils; - import org.apache.xmlgraphics.fonts.Glyphs; import org.apache.xmlgraphics.util.io.ASCIIHexOutputStream; import org.apache.xmlgraphics.util.io.IOUtils; @@ -64,7 +62,7 @@ public static void embedType1Font(PSGenerator gen, InputStream in) throws IOExce int dataSegLen = 0; switch (segType) { case 1: //ASCII - dataSegLen = EndianUtils.readSwappedInteger(in); + dataSegLen = readLittleEndianInt(in); BufferedReader reader = new BufferedReader( new java.io.InputStreamReader( @@ -75,7 +73,7 @@ public static void embedType1Font(PSGenerator gen, InputStream in) throws IOExce } break; case 2: //binary - dataSegLen = EndianUtils.readSwappedInteger(in); + dataSegLen = readLittleEndianInt(in); SubInputStream sin = new SubInputStream(in, dataSegLen); ASCIIHexOutputStream hexOut = new ASCIIHexOutputStream(gen.getOutputStream()); @@ -90,6 +88,17 @@ public static void embedType1Font(PSGenerator gen, InputStream in) throws IOExce } } + private static int readLittleEndianInt(InputStream in) throws IOException { + int ch1 = in.read(); + int ch2 = in.read(); + int ch3 = in.read(); + int ch4 = in.read(); + if ((ch1 | ch2 | ch3 | ch4) < 0) { + throw new IOException("Unexpected end of stream while reading integer"); + } + return (ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1; + } + /** the PSResource representing the WinAnsiEncoding. */ public static final PSResource WINANSI_ENCODING_RESOURCE = new PSResource(PSResource.TYPE_ENCODING, "WinAnsiEncoding"); From 682d2e36b257484b8e22f9cfa42c570a2efba5b1 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Nov 2025 14:39:14 +0300 Subject: [PATCH 5/6] XGC-148: replace commons.io.output.ByteArrayOutputStream with java.io.ByteArrayOutputStream --- .../image/loader/impl/ImageConverterRendered2PNG.java | 3 +-- .../xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java | 2 +- .../java/org/apache/xmlgraphics/xmp/XMPPacketParser.java | 3 +-- .../writer/imageio/ImageIOTIFFImageWriterTestCase.java | 3 +-- .../xmlgraphics/ps/ImageEncodingHelperTestCase.java | 8 ++++---- .../xmlgraphics/util/io/ASCII85InputStreamTestCase.java | 5 ++--- .../xmlgraphics/util/io/ASCII85OutputStreamTestCase.java | 5 ++--- src/tools/resources/findbugs/exclusions.xml | 7 +++++-- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java index 7f2041ce..3db85ced 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterRendered2PNG.java @@ -19,11 +19,10 @@ package org.apache.xmlgraphics.image.loader.impl; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Map; -import org.apache.commons.io.output.ByteArrayOutputStream; - import org.apache.xmlgraphics.image.loader.Image; import org.apache.xmlgraphics.image.loader.ImageException; import org.apache.xmlgraphics.image.loader.ImageFlavor; diff --git a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java index 8eeb9a76..75830d42 100644 --- a/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java +++ b/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderRawJPEG.java @@ -22,6 +22,7 @@ import java.awt.color.ColorSpace; import java.awt.color.ICC_Profile; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.IOException; import java.util.Map; @@ -29,7 +30,6 @@ import javax.imageio.stream.ImageInputStream; import javax.xml.transform.Source; -import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java b/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java index 5de696b5..3bb20bd7 100644 --- a/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java +++ b/src/main/java/org/apache/xmlgraphics/xmp/XMPPacketParser.java @@ -20,6 +20,7 @@ package org.apache.xmlgraphics.xmp; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -28,8 +29,6 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.stream.StreamSource; -import org.apache.commons.io.output.ByteArrayOutputStream; - /** * This class is a parser for XMP packets. By default, it tries to locate the first XMP packet * it finds and parses it. diff --git a/src/test/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriterTestCase.java b/src/test/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriterTestCase.java index 95287d43..47ecf4d9 100644 --- a/src/test/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriterTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/image/writer/imageio/ImageIOTIFFImageWriterTestCase.java @@ -25,6 +25,7 @@ import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; import java.io.IOException; import javax.imageio.metadata.IIOMetadata; @@ -35,8 +36,6 @@ import org.w3c.dom.Node; -import org.apache.commons.io.output.ByteArrayOutputStream; - import org.apache.xmlgraphics.image.loader.ImageSize; import org.apache.xmlgraphics.image.writer.Endianness; import org.apache.xmlgraphics.image.writer.ImageIOCheckUtility; diff --git a/src/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java b/src/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java index 954ace31..d068736a 100644 --- a/src/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java @@ -26,6 +26,7 @@ import java.awt.image.DataBuffer; import java.awt.image.DirectColorModel; import java.awt.image.WritableRaster; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; @@ -33,14 +34,13 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.apache.commons.io.output.ByteArrayOutputStream; - public class ImageEncodingHelperTestCase { private BufferedImage prepareImage(BufferedImage image) { @@ -79,7 +79,7 @@ public void testEncodeRenderedImageWithDirectColorModelAsRGB() throws IOExceptio ByteArrayOutputStream nonoptimized = new ByteArrayOutputStream(); ImageEncodingHelper.encodeRenderedImageAsRGB(image, nonoptimized); - assertTrue(Arrays.equals(nonoptimized.toByteArray(), optimized.toByteArray())); + assertArrayEquals(nonoptimized.toByteArray(), optimized.toByteArray()); } @@ -148,6 +148,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable { byte[] expectedByteArray = new byte[27]; Arrays.fill(expectedByteArray, (byte) expectedValue); - assertTrue(Arrays.equals(expectedByteArray, optimized.toByteArray())); + assertArrayEquals(expectedByteArray, optimized.toByteArray()); } } diff --git a/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java b/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java index 4a921ca2..1a33aaa8 100644 --- a/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/util/io/ASCII85InputStreamTestCase.java @@ -20,6 +20,7 @@ package org.apache.xmlgraphics.util.io; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -28,8 +29,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import org.apache.commons.io.output.ByteArrayOutputStream; - import org.apache.xmlgraphics.util.HexUtil; /** @@ -61,7 +60,7 @@ private String encode(byte[] data, int len) throws Exception { java.io.OutputStream out = new ASCII85OutputStream(baout); out.write(data, 0, len); out.close(); - return new String(baout.toByteArray(), "US-ASCII"); + return baout.toString("US-ASCII"); } diff --git a/src/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java b/src/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java index cb688b1b..bae48ade 100644 --- a/src/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java +++ b/src/test/java/org/apache/xmlgraphics/util/io/ASCII85OutputStreamTestCase.java @@ -19,14 +19,13 @@ package org.apache.xmlgraphics.util.io; +import java.io.ByteArrayOutputStream; import java.io.OutputStream; import org.junit.Test; import static org.junit.Assert.assertEquals; -import org.apache.commons.io.output.ByteArrayOutputStream; - /** * Test case for ASCII85OutputStream */ @@ -51,7 +50,7 @@ private String encode(byte[] data, int len) throws Exception { OutputStream out = new ASCII85OutputStream(baout); out.write(data, 0, len); out.close(); - return new String(baout.toByteArray(), "US-ASCII"); + return baout.toString("US-ASCII"); } /** diff --git a/src/tools/resources/findbugs/exclusions.xml b/src/tools/resources/findbugs/exclusions.xml index 768f5c13..451889e2 100644 --- a/src/tools/resources/findbugs/exclusions.xml +++ b/src/tools/resources/findbugs/exclusions.xml @@ -196,6 +196,9 @@ - - + + + + + From 9903f8ccb469fc1f73b5ae5df808e1f16f80f6d0 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Thu, 6 Nov 2025 14:42:44 +0300 Subject: [PATCH 6/6] XGC-148: remove commons-io Maven dependency --- lib/README.txt | 9 -- lib/commons-io.LICENSE.txt | 203 ------------------------------------- lib/commons-io.NOTICE.txt | 6 -- pom.xml | 5 - 4 files changed, 223 deletions(-) delete mode 100644 lib/commons-io.LICENSE.txt delete mode 100644 lib/commons-io.NOTICE.txt diff --git a/lib/README.txt b/lib/README.txt index 22ff3e43..8a9715af 100644 --- a/lib/README.txt +++ b/lib/README.txt @@ -11,15 +11,6 @@ http://www.apache.org/licenses/ Normal Dependencies ---------------------- -- Apache Commons IO - - commons-io-*.jar - http://jakarta.apache.org/commons/io/ - (I/O routines) - - Apache License v2.0 - - - Apache Commons Logging commons-logging-*.jar diff --git a/lib/commons-io.LICENSE.txt b/lib/commons-io.LICENSE.txt deleted file mode 100644 index 6b0b1270..00000000 --- a/lib/commons-io.LICENSE.txt +++ /dev/null @@ -1,203 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/lib/commons-io.NOTICE.txt b/lib/commons-io.NOTICE.txt deleted file mode 100644 index ce3b94a0..00000000 --- a/lib/commons-io.NOTICE.txt +++ /dev/null @@ -1,6 +0,0 @@ -Apache Jakarta Commons IO -Copyright 2001-2007 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - diff --git a/pom.xml b/pom.xml index b91efa33..c1705625 100644 --- a/pom.xml +++ b/pom.xml @@ -45,11 +45,6 @@ - - commons-io - commons-io - 2.17.0 - commons-logging commons-logging