You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2021/07/08 13:48:52 UTC
[tika] branch main updated: TIKA-3469 -- read bytes until 'ready'
byte in PipesClient.
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/main by this push:
new 4f909bd TIKA-3469 -- read bytes until 'ready' byte in PipesClient.
4f909bd is described below
commit 4f909bd52ffa99da310c7233403e47f01101c1f6
Author: tallison <ta...@apache.org>
AuthorDate: Thu Jul 8 09:48:32 2021 -0400
TIKA-3469 -- read bytes until 'ready' byte in PipesClient.
---
.../java/org/apache/tika/pipes/PipesClient.java | 27 ++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/tika-core/src/main/java/org/apache/tika/pipes/PipesClient.java b/tika-core/src/main/java/org/apache/tika/pipes/PipesClient.java
index c4551a3..1d12f2c 100644
--- a/tika-core/src/main/java/org/apache/tika/pipes/PipesClient.java
+++ b/tika-core/src/main/java/org/apache/tika/pipes/PipesClient.java
@@ -44,7 +44,7 @@ import org.apache.tika.utils.ProcessUtils;
public class PipesClient implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(PipesClient.class);
-
+ private static final int MAX_BYTES_BEFORE_READY = 20000;
private Process process;
private final PipesConfigBase pipesConfig;
private DataOutputStream output;
@@ -232,9 +232,28 @@ public class PipesClient implements Closeable {
//wait for ready signal
FutureTask<Integer> futureTask = new FutureTask<>(() -> {
int b = input.read();
- if (b != PipesServer.READY) {
- throw new RuntimeException("Couldn't start server: " + b +
- " Make absolutely certain that your logger is not writing to stdout.");
+ int read = 1;
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ while (read < MAX_BYTES_BEFORE_READY && b != PipesServer.READY) {
+ if (b == -1) {
+ throw new RuntimeException("Couldn't start server: " +
+ "read EOF before 'ready' byte.\n" +
+ " Make absolutely certain that your logger is not writing to stdout.");
+ }
+ bos.write(b);
+ b = input.read();
+ read++;
+ }
+ if (read >= MAX_BYTES_BEFORE_READY) {
+ throw new RuntimeException("Couldn't start server: read too many bytes before " +
+ "'ready' byte.\n" +
+ " Make absolutely certain that your logger is not writing to stdout.\n" +
+ " Message read: " + new String(bos.toByteArray(),
+ StandardCharsets.ISO_8859_1));
+ }
+ if (bos.size() > 0) {
+ LOG.warn("From forked process before start byte: {}",
+ new String(bos.toByteArray(), StandardCharsets.ISO_8859_1));
}
return 1;
});