Skip to content

Commit

Permalink
TIKA-4238: replace deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
THausherr committed Apr 6, 2024
1 parent 3b6b5ed commit cab022b
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void embed(final Metadata metadata, final InputStream inputStream,
process = Runtime.getRuntime().exec(cmd.toArray(new String[]{}));
}

UnsynchronizedByteArrayOutputStream stdErrOutputStream = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream stdErrOutputStream = UnsynchronizedByteArrayOutputStream.builder().get();

try {
sendStdErrToOutputStream(process, stdErrOutputStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private PipesResult actuallyProcess(FetchEmitTuple t) throws InterruptedExceptio
final PipesResult[] intermediateResult = new PipesResult[1];
FutureTask<PipesResult> futureTask = new FutureTask<>(() -> {

UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos)) {
objectOutputStream.writeObject(t);
}
Expand Down Expand Up @@ -438,7 +438,7 @@ private void restart() throws IOException, InterruptedException, TimeoutExceptio
output = new DataOutputStream(process.getOutputStream());

//wait for ready signal
final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
final UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
FutureTask<Integer> futureTask = new FutureTask<>(() -> {
int b = input.read();
int read = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ protected void initializeResources() throws TikaException, IOException, SAXExcep

private void writeIntermediate(EmitKey emitKey, Metadata metadata) {
try {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos)) {
objectOutputStream.writeObject(metadata);
}
Expand All @@ -690,7 +690,7 @@ private void writeIntermediate(EmitKey emitKey, Metadata metadata) {

private void write(EmitData emitData) {
try {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos)) {
objectOutputStream.writeObject(emitData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testBasic(@TempDir Path tmp) throws Exception {

PipesServer pipesServer = new PipesServer(tikaConfig,
new UnsynchronizedByteArrayInputStream(new byte[0]),
new PrintStream(new UnsynchronizedByteArrayOutputStream(), true,
new PrintStream(UnsynchronizedByteArrayOutputStream.builder().get(), true,
StandardCharsets.UTF_8.name()),
-1, 30000, 30000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Set<MediaType> getSupportedTypes(ParseContext context) {
*/
public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
ParseContext context) throws IOException, SAXException, TikaException {
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(stream, os);

String name = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
private String computePoT(File input) throws IOException {

CommandLine cmdLine = new CommandLine("pooled-time-series");
try (UnsynchronizedByteArrayOutputStream outputStream = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream outputStream = UnsynchronizedByteArrayOutputStream.builder().get()) {
cmdLine.addArgument("-f");
cmdLine.addArgument(input.getAbsolutePath());
LOG.trace("Executing: {}", cmdLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public void body(BodyDescriptor body, InputStream is) throws MimeException, IOEx
//if we're in a multipart/alternative or any one of its children
//add the bodypart to the latest that was added
if (!extractAllAlternatives && alternativePartBuffer.size() > 0) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(is, bos);
alternativePartBuffer.peek().children.add(new BodyContents(submd, bos.toByteArray()));
} else if (!extractAllAlternatives && parts.size() < 2) {
//if you're at the first level of embedding
//and you're not in an alternative part block
//and you're text/html, put that in the body of the email
//otherwise treat as a regular attachment
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(is, bos);
final byte[] bytes = bos.toByteArray();
if (detectInlineTextOrHtml(submd, bytes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean shouldTranslate(InputStream inputStream, Metadata metadata) throw
public InputStream translate(InputStream inputStream, Metadata metadata) throws IOException {
String contentType = metadata.get(org.apache.tika.metadata.HttpHeaders.CONTENT_TYPE);
if ("application/vnd.openxmlformats-officedocument.oleObject".equals(contentType)) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(inputStream, bos);
POIFSFileSystem poifs = new POIFSFileSystem(bos.toInputStream());
OfficeParser.POIFSDocumentType type = OfficeParser.POIFSDocumentType.detectType(poifs);
Expand Down Expand Up @@ -90,7 +90,7 @@ public InputStream translate(InputStream inputStream, Metadata metadata) throws
tin.getOpenContainer() instanceof DirectoryEntry) {
POIFSFileSystem fs = new POIFSFileSystem();
copy((DirectoryEntry) tin.getOpenContainer(), fs.getRoot());
try (UnsynchronizedByteArrayOutputStream bos2 = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos2 = UnsynchronizedByteArrayOutputStream.builder().get()) {
fs.writeFilesystem(bos2);
return bos2.toInputStream();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private void extractOCXName(DirectoryEntry dir, Metadata metadata) {
if (!e.isDocumentEntry()) {
return;
}
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (DocumentInputStream dis = new DocumentInputStream((DocumentEntry) e)) {
IOUtils.copy(dis, bos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public List<String> enumerateChm() {
*/
public byte[] extractChmEntry(DirectoryListingEntry directoryListingEntry)
throws TikaException {
UnsynchronizedByteArrayOutputStream buffer = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream buffer = UnsynchronizedByteArrayOutputStream.builder().get();
ChmLzxBlock lzxBlock = null;
try {
/* UNCOMPRESSED type is easiest one */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void dump() throws TikaException, SAXException {
private void dumpAscii() throws SAXException, TikaException {
try {
oneNoteDirectFileResource.position(0);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
long sz = oneNoteDirectFileResource.size();
long pos;
while ((pos = oneNoteDirectFileResource.position()) != sz) {
Expand Down Expand Up @@ -108,7 +108,7 @@ private void dumpAscii() throws SAXException, TikaException {
private void dumpUtf16LE() throws SAXException, TikaException {
try {
oneNoteDirectFileResource.position(0);
UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream os = UnsynchronizedByteArrayOutputStream.builder().get();
long sz = oneNoteDirectFileResource.size();
long bufSize = BUFFER_SIZE;
// Make sure the buffer size is a multiple of 2.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected RTFEmbObjHandler(ContentHandler handler, Metadata metadata, ParseConte
int memoryLimitInKb) {
this.handler = handler;
this.embeddedDocumentUtil = new EmbeddedDocumentUtil(context);
os = new UnsynchronizedByteArrayOutputStream();
os = UnsynchronizedByteArrayOutputStream.builder().get();
this.memoryLimitInKb = memoryLimitInKb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private byte[] handleEmbeddedPOIFS(InputStream is, Metadata metadata,

if (root.hasEntry("Package")) {
Entry ooxml = root.getEntry("Package");
UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
try (BoundedInputStream bis = new BoundedInputStream(memoryLimitInKb * 1024,
new DocumentInputStream((DocumentEntry) ooxml))) {
IOUtils.copy(bis, out);
Expand Down Expand Up @@ -191,7 +191,7 @@ private byte[] handleEmbeddedPOIFS(InputStream is, Metadata metadata,
}
} else {

UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream out = UnsynchronizedByteArrayOutputStream.builder().get();
is.reset();
BoundedInputStream bis = new BoundedInputStream(memoryLimitInKb * 1024, is);
IOUtils.copy(is, out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ protected void processImage(PDImage pdImage, int imageNumber)
}

if (embeddedDocumentExtractor.shouldParseEmbedded(metadata)) {
UnsynchronizedByteArrayOutputStream buffer = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream buffer = UnsynchronizedByteArrayOutputStream.builder().get();
if (pdImage instanceof PDImageXObject) {
//extract the metadata contained outside of the image
PDMetadataExtractor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public MediaType detect(InputStream input, Metadata metadata) throws IOException
private MediaType detectSpecialization(InputStream input, Metadata metadata) throws IOException {

int buffSize = 1024;
UnsynchronizedByteArrayOutputStream gzippedBytes = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream gzippedBytes = UnsynchronizedByteArrayOutputStream.builder().get();
try {
IOUtils.copyRange(input, buffSize, gzippedBytes);
} catch (IOException e) {
//swallow
} finally {
input.reset();
}
UnsynchronizedByteArrayOutputStream bytes = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bytes = UnsynchronizedByteArrayOutputStream.builder().get();
try (InputStream is = new
GzipCompressorInputStream(new UnsynchronizedByteArrayInputStream(gzippedBytes.toByteArray()))) {
int c = is.read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public static void setMaxXMPMMHistory(int maxEvents) {
}

public void parse(InputStream file) throws IOException, TikaException {
UnsynchronizedByteArrayOutputStream xmpraw = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream xmpraw = UnsynchronizedByteArrayOutputStream.builder().get();
if (!scanner.parse(file, xmpraw)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public MediaType streamingDetectUpdate(ZipArchiveEntry zae, InputStream zis,
if ("mimetype".equals(name)) {
//can't rely on zae.getSize to determine if there is any
//content here. :(
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
BoundedInputStream bis = new BoundedInputStream(MAX_MIME_TYPE, zis);
IOUtils.copy(bis, bos);
//do anything with an inputstream > MAX_MIME_TYPE?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public MediaType streamingDetectUpdate(ZipArchiveEntry zae, InputStream zis,
//"as is" can cause the iteration of the entries to stop early
//without exception or warning. So, copy the full stream, then
//process. TIKA-3061
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
BoundedInputStream bis = new BoundedInputStream(MAX_MANIFEST, zis);
IOUtils.copy(bis, bos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void emit(String emitKey, List<Metadata> metadataList)
}
//TODO: estimate size of metadata list. Above a certain size,
//create a temp file?
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8)) {
JsonMetadataList.toJson(metadataList, writer);
} catch (IOException e) {
Expand Down Expand Up @@ -126,7 +126,7 @@ public void emit(String path, InputStream is, Metadata userMetadata)
LOGGER.debug("relying on the content-length set in the metadata object: {}", length);
write(path, userMetadata, is, length);
} else {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(is, bos);
write(path, userMetadata, bos.toByteArray());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void emit(String emitKey, List<Metadata> metadataList)
if (metadataList == null || metadataList.size() == 0) {
throw new TikaEmitterException("metadata list must not be null or of size 0");
}
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
try (Writer writer = new OutputStreamWriter(bos, StandardCharsets.UTF_8)) {
JsonMetadataList.toJson(metadataList, writer);
} catch (IOException e) {
Expand All @@ -99,7 +99,7 @@ public void emit(String path, InputStream is, Metadata userMetadata)
if (is instanceof TikaInputStream && ((TikaInputStream) is).hasFile()) {
write(path, userMetadata, Files.readAllBytes(((TikaInputStream) is).getPath()));
} else {
try (UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
try (UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get()) {
IOUtils.copy(is, bos);
write(path, userMetadata, bos.toByteArray());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void emit(String emitKey, List<Metadata> metadataList)
}

if (!spoolToTemp) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
try (Writer writer = new BufferedWriter(
new OutputStreamWriter(bos, StandardCharsets.UTF_8))) {
JsonMetadataList.toJson(metadataList, writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private String responseToString(HttpResponse response) {
return "";
}
try (InputStream is = response.getEntity().getContent()) {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copyLarge(is, bos, 0, maxErrMsgSize);
return bos.toString(StandardCharsets.UTF_8);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private Map<String, byte[]> process(InputStream is, @Context HttpHeaders httpHea
//we need to add this to allow for "inline" use of other parsers.
pc.set(Parser.class, parser);
ContentHandler ch;
UnsynchronizedByteArrayOutputStream text = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream text = UnsynchronizedByteArrayOutputStream.builder().get();

if (saveAll) {
ch = new BodyContentHandler(
Expand All @@ -165,7 +165,7 @@ private Map<String, byte[]> process(InputStream is, @Context HttpHeaders httpHea
if (saveAll) {
files.put(TEXT_FILENAME, text.toByteArray());

UnsynchronizedByteArrayOutputStream metaStream = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream metaStream = UnsynchronizedByteArrayOutputStream.builder().get();
metadataToCsv(metadata, metaStream);

files.put(META_FILENAME, metaStream.toByteArray());
Expand Down Expand Up @@ -194,7 +194,7 @@ public boolean shouldParseEmbedded(Metadata metadata) {

public void parseEmbedded(InputStream inputStream, ContentHandler contentHandler,
Metadata metadata, boolean b) throws SAXException, IOException {
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos = UnsynchronizedByteArrayOutputStream.builder().get();

BoundedInputStream bis = new BoundedInputStream(unpackMaxBytes, inputStream);
IOUtils.copy(bis, bos);
Expand Down Expand Up @@ -231,7 +231,7 @@ public void parseEmbedded(InputStream inputStream, ContentHandler contentHandler
if (embeddedStreamTranslator.shouldTranslate(is, metadata)) {
InputStream translated = embeddedStreamTranslator
.translate(new UnsynchronizedByteArrayInputStream(data), metadata);
UnsynchronizedByteArrayOutputStream bos2 = new UnsynchronizedByteArrayOutputStream();
UnsynchronizedByteArrayOutputStream bos2 = UnsynchronizedByteArrayOutputStream.builder().get();
IOUtils.copy(translated, bos2);
data = bos2.toByteArray();
}
Expand Down

0 comments on commit cab022b

Please sign in to comment.