Skip to content

Commit 1a7a43b

Browse files
committed
[refactor] Use new APIs from commons-io
1 parent 5e74895 commit 1a7a43b

File tree

12 files changed

+21
-19
lines changed

12 files changed

+21
-19
lines changed

extensions/exquery/restxq/src/main/java/org/exist/extensions/exquery/restxq/impl/RestXqServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected Sequence extractRequestBody(final HttpRequest request) throws RestXqSe
135135
try {
136136

137137
//first, get the content of the request
138-
is = new CloseShieldInputStream(request.getInputStream());
138+
is = CloseShieldInputStream.wrap(request.getInputStream());
139139

140140
//if marking is not supported, we have to cache the input stream, so we can reread it, as we may use it twice (once for xml attempt and once for string attempt)
141141
if (!is.markSupported()) {
@@ -261,7 +261,7 @@ private DocumentImpl parseAsXml(final InputStream is) {
261261
//try and construct xml document from input stream, we use eXist's in-memory DOM implementation
262262

263263
//we have to use CloseShieldInputStream otherwise the parser closes the stream and we cant later reread
264-
final InputSource src = new InputSource(new CloseShieldInputStream(is));
264+
final InputSource src = new InputSource(CloseShieldInputStream.wrap(is));
265265

266266
reader = getBrokerPool().getParserPool().borrowXMLReader();
267267
final MemTreeBuilder builder = new MemTreeBuilder();
@@ -287,7 +287,7 @@ private DocumentImpl parseAsXml(final InputStream is) {
287287

288288
private static StringValue parseAsString(final InputStream is, final String encoding) throws IOException {
289289
final String s;
290-
try (final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(4096)) {
290+
try (final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().setBufferSize(4096).get()) {
291291
bos.write(is);
292292
s = new String(bos.toByteArray(), encoding);
293293
}

extensions/indexes/spatial/src/main/java/org/exist/xquery/modules/spatial/FunGeometricProperties.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import org.locationtech.jts.io.WKBWriter;
5252
import org.locationtech.jts.io.WKTWriter;
5353

54+
import java.io.IOException;
55+
5456
/**
5557
* @author <a href="mailto:[email protected]">Pierrick Brihaye</a>
5658
* @author ljo
@@ -341,7 +343,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
341343
result = new StringValue(this, wktWriter.write(geometry));
342344
} else if (isCalledAs("getEPSG4326WKB")) {
343345
byte data[] = wkbWriter.write(geometry);
344-
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(data), this);
346+
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), this);
345347
} else if (isCalledAs("getEPSG4326MinX")) {
346348
result = new DoubleValue(this, geometry.getEnvelopeInternal().getMinX());
347349
} else if (isCalledAs("getEPSG4326MaxX")) {
@@ -361,7 +363,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
361363
result = new StringValue(this, wktWriter.write(geometry));
362364
} else if (isCalledAs("getWKB")) {
363365
byte data[] = wkbWriter.write(geometry);
364-
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), new UnsynchronizedByteArrayInputStream(data), this);
366+
return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(), UnsynchronizedByteArrayInputStream.builder().setByteArray(data).get(), this);
365367
} else if (isCalledAs("getMinX")) {
366368
result = new DoubleValue(this, geometry.getEnvelopeInternal().getMinX());
367369
} else if (isCalledAs("getMaxX")) {
@@ -391,7 +393,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
391393
throw new XPathException(this, "Unknown spatial property: " + getName().getLocalPart());
392394
}
393395
}
394-
} catch (SpatialIndexException e) {
396+
} catch (SpatialIndexException | IOException e) {
395397
logger.error(e.getMessage());
396398
throw new XPathException(this, e);
397399
}

extensions/modules/exi/src/main/java/org/exist/xquery/modules/exi/EncodeExiFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence)
8787
if(args[0].isEmpty()) {
8888
return Sequence.EMPTY_SEQUENCE;
8989
}
90-
try (final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
90+
try (final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
9191
EXISerializer exiSerializer;
9292
if(args.length > 1) {
9393
if(!args[1].isEmpty()) {

extensions/modules/file/src/test/java/org/exist/xquery/modules/file/EmbeddedBinariesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ protected boolean isBooleanType(final Item item) throws IOException {
144144
@Override
145145
protected byte[] getBytes(final Item item) throws IOException {
146146
if (item instanceof Base64BinaryDocument doc) {
147-
try (final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
147+
try (final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
148148
doc.streamBinaryTo(baos);
149149
return baos.toByteArray();
150150
}
151151
} else {
152152
final BinaryValueFromFile file = (BinaryValueFromFile) item;
153-
try (final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
153+
try (final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
154154
file.streamBinaryTo(baos);
155155
return baos.toByteArray();
156156
}

extensions/modules/file/src/test/java/org/exist/xquery/modules/file/RestBinariesTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void readAndStreamBinarySax() throws IOException, JAXBException {
8888
final HttpResponse response = postXquery(query);
8989

9090
final HttpEntity entity = response.getEntity();
91-
try(final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
91+
try(final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
9292
entity.writeTo(baos);
9393

9494
assertArrayEquals(Files.readAllBytes(tmpInFile), Base64.decodeBase64(baos.toByteArray()));
@@ -113,7 +113,7 @@ public void readAndStreamBinaryRaw() throws IOException, JAXBException {
113113
final HttpResponse response = postXquery(query);
114114

115115
final HttpEntity entity = response.getEntity();
116-
try(final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
116+
try(final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
117117
entity.writeTo(baos);
118118

119119
assertArrayEquals(Files.readAllBytes(tmpInFile), baos.toByteArray());
@@ -168,7 +168,7 @@ private HttpResponse postXquery(final String xquery) throws JAXBException, IOExc
168168
final Marshaller marshaller = jaxbContext.createMarshaller();
169169

170170
final HttpResponse response;
171-
try(final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
171+
try(final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
172172
marshaller.marshal(query, baos);
173173
response = executor.execute(Request.Post(getRestUrl() + "/db/")
174174
.bodyByteArray(baos.toByteArray(), ContentType.APPLICATION_XML)

extensions/modules/image/src/main/java/org/exist/xquery/modules/image/CropFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathExce
168168
g.dispose();
169169
}
170170

171-
try (final UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
171+
try (final UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get()) {
172172
ImageIO.write(bImage, formatName, os);
173173

174174
//return the new croped image data

extensions/modules/image/src/main/java/org/exist/xquery/modules/image/GetThumbnailsFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public Sequence eval(Sequence[] args, Sequence contextSequence)
270270
}
271271

272272
if (isSaveToDataBase) {
273-
os = new UnsynchronizedByteArrayOutputStream();
273+
os = UnsynchronizedByteArrayOutputStream.builder().get();
274274
try {
275275
ImageIO.write(bImage, "jpg", os);
276276
} catch (Exception e) {

extensions/modules/image/src/main/java/org/exist/xquery/modules/image/ScaleFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
187187
final BufferedImage bImage = ImageModule.createThumb(image, maxHeight, maxWidth, renderingHints);
188188

189189
//get the new scaled image
190-
try (final UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
190+
try (final UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get()) {
191191
ImageIO.write(bImage, formatName, os);
192192

193193
//return the new scaled image data

extensions/modules/xslfo/src/main/java/org/exist/xquery/modules/xslfo/RenderFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
122122
}
123123

124124
ProcessorAdapter adapter = null;
125-
try (final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
125+
try (final UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get()) {
126126
adapter = ((XSLFOModule) getParentModule()).getProcessorAdapter();
127127

128128
final NodeValue processorConfig = args.length == 4 ? (NodeValue) args[3].itemAt(0) : null;

extensions/security/ldap/src/test/java/org/exist/security/realm/ldap/LDAPRealmTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class LDAPRealmTest {
5858
*/
5959
@BeforeClass
6060
public static void setUpBeforeClass() throws Exception {
61-
try (final InputStream is = new UnsynchronizedByteArrayInputStream(config.getBytes(UTF_8))) {
61+
try (final InputStream is = UnsynchronizedByteArrayInputStream.builder().setByteArray(config.getBytes(UTF_8)).get()) {
6262
Configuration config = Configurator.parse(is);
6363
realm = new LDAPRealm(null, config);
6464
}

0 commit comments

Comments
 (0)