Skip to content

Commit ac11d8e

Browse files
committed
[refactor] Use new APIs from commons-io
1 parent a643fc4 commit ac11d8e

File tree

12 files changed

+20
-19
lines changed

12 files changed

+20
-19
lines changed

extensions/exiftool/src/main/java/org/exist/exiftool/xquery/MetadataFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private Sequence exifToolExtract(final Path binaryFile) throws XPathException {
156156
try {
157157
final Process p = Runtime.getRuntime().exec(module.getPerlPath() + " " + module.getExiftoolPath() + " -X -struct " + binaryFile.toAbsolutePath());
158158
try(final InputStream stdIn = p.getInputStream();
159-
final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
159+
final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
160160

161161
//buffer stdin
162162
baos.write(stdIn);
@@ -179,7 +179,7 @@ private Sequence exifToolWebExtract(final URI uri) throws XPathException {
179179
final Process p = Runtime.getRuntime().exec(module.getExiftoolPath()+" -fast -X -");
180180

181181
try(final InputStream stdIn = p.getInputStream();
182-
final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
182+
final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
183183

184184
try(final OutputStream stdOut = p.getOutputStream()) {
185185
final Source src = SourceFactory.getSource(context.getBroker(), null, uri.toString(), false);

extensions/expath/src/main/java/org/expath/exist/ZipFileFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private Sequence updateZip(XmldbURI uri, String[] paths, BinaryValue[] binaries)
137137
binariesTable.put(paths[i], binaries[i]);
138138
}
139139

140-
try(final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream())
140+
try(final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get())
141141
{
142142
zis = zipFileSource.getStream();
143143
ZipOutputStream zos = new ZipOutputStream(baos); // zos is the output - the result

extensions/expath/src/main/java/org/expath/tools/model/exist/EXistSequence.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void serialize(final OutputStream out, final SerialParameters params) thr
8282
props.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
8383

8484
final String encoding = props.getProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
85-
try(final Writer writer = new OutputStreamWriter(new CloseShieldOutputStream(out), encoding)) {
85+
try(final Writer writer = new OutputStreamWriter(CloseShieldOutputStream.wrap(out), encoding)) {
8686
final XQuerySerializer xqSerializer = new XQuerySerializer(context.getBroker(), props, writer);
8787
xqSerializer.serialize(sequence);
8888
} catch(final SAXException | IOException | XPathException e) {

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/AbstractCompressFunction.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence)
120120
encoding = StandardCharsets.UTF_8;
121121
}
122122

123-
try(final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
123+
try(final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
124124
OutputStream os = stream(baos, encoding)) {
125125

126126
// iterate through the argument sequence
@@ -140,7 +140,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence)
140140
((DeflaterOutputStream)os).finish();
141141
}
142142

143-
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(baos.toByteArray()), this);
143+
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), UnsynchronizedByteArrayInputStream.builder().setByteArray(baos.toByteArray()).get(), this);
144144
}
145145
} catch (final UnsupportedCharsetException | IOException e) {
146146
throw new XPathException(this, e.getMessage(), e);
@@ -412,7 +412,8 @@ private void compressResource(OutputStream os, DocumentImpl doc, boolean useHier
412412
} else if (doc.getResourceType() == DocumentImpl.BINARY_FILE && doc.getContentLength() > 0) {
413413
// binary file
414414
try (final InputStream is = context.getBroker().getBinaryResource((BinaryDocument) doc);
415-
final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(doc.getContentLength() == -1 ? 1024 : (int) doc.getContentLength())) {
415+
416+
final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(doc.getContentLength() == -1 ? 1024 : (int) doc.getContentLength()).get()) {
416417
baos.write(is);
417418
value = baos.toByteArray();
418419
}

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/AbstractExtractFunction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ protected Sequence processCompressedEntry(String name, boolean isDirectory, Inpu
188188

189189
//copy the input data
190190
final byte[] entryData;
191-
try (final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
191+
try (final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
192192
baos.write(is);
193193
entryData = baos.toByteArray();
194194
}
195195

196-
try (final InputStream bis = new UnsynchronizedByteArrayInputStream(entryData)) {
196+
try (final InputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(entryData).get()) {
197197
NodeValue content = ModuleUtils.streamToXML(context, bis, this);
198198
try (Resource resource = target.createResource(name, XMLResource.class)) {
199199
ContentHandler handler = ((XMLResource) resource).setContentAsSAX();
@@ -214,17 +214,17 @@ protected Sequence processCompressedEntry(String name, boolean isDirectory, Inpu
214214

215215
//copy the input data
216216
final byte[] entryData;
217-
try (final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
217+
try (final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
218218
baos.write(is);
219219
entryData = baos.toByteArray();
220220
}
221221

222222
//try and parse as xml, fall back to binary
223-
try (final InputStream bis = new UnsynchronizedByteArrayInputStream(entryData)) {
223+
try (final InputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(entryData).get()) {
224224
uncompressedData = ModuleUtils.streamToXML(context, bis, this);
225225
} catch (SAXException saxe) {
226226
if (entryData.length > 0) {
227-
try (final InputStream bis = new UnsynchronizedByteArrayInputStream(entryData)) {
227+
try (final InputStream bis = UnsynchronizedByteArrayInputStream.builder().setByteArray(entryData).get()) {
228228
uncompressedData = BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), bis, this);
229229
}
230230
}

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/DeflateFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
9595
Deflater defl = new Deflater(java.util.zip.Deflater.DEFAULT_COMPRESSION, rawflag);
9696

9797
// deflate the data
98-
try(final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
98+
try(final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
9999
DeflaterOutputStream dos = new DeflaterOutputStream(baos, defl)) {
100100
bin.streamBinaryTo(dos);
101101
dos.flush();

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/GZipFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
7676
BinaryValue bin = (BinaryValue) args[0].itemAt(0);
7777

7878
// gzip the data
79-
try(final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
79+
try(final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
8080
final GZIPOutputStream gzos = new GZIPOutputStream(baos)) {
8181
bin.streamBinaryTo(gzos);
8282

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/InflateFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
9292

9393
// uncompress the data
9494
try(final InflaterInputStream iis = new InflaterInputStream(bin.getInputStream(), infl);
95-
final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
95+
final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
9696
int read = -1;
9797
final byte[] b = new byte[4096];
9898
while ((read = iis.read(b)) != -1) {

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/UnGZipFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
7777
//TODO(AR) just pass the GZIPInputStream straight into BinaryValueFromInputStream.getInstance
7878
// ungzip the data
7979
try(final GZIPInputStream gzis = new GZIPInputStream(bin.getInputStream());
80-
final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
80+
final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
8181
baos.write(gzis);
8282
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), baos.toInputStream(), this);
8383
} catch(final IOException ioe) {

extensions/modules/compression/src/main/java/org/exist/xquery/modules/compression/UnTarFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected Sequence processCompressedData(final BinaryValue compressedData, final
126126

127127
final Sequence results = new ValueSequence();
128128

129-
while((entry = tis.getNextTarEntry()) != null) {
129+
while((entry = tis.getNextEntry()) != null) {
130130
final Sequence processCompressedEntryResults = processCompressedEntry(entry.getName(), entry.isDirectory(), tis, filterParam, storeParam);
131131
results.addAll(processCompressedEntryResults);
132132
}

0 commit comments

Comments
 (0)