aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/util/io
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/io')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java41
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/ByteBufferInputStream.java137
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/CountingOutputStream.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/DisabledOutputStream.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/LimitedInputStream.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/SilentInputStream.java49
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeOutputStream.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/ThrowingPrintWriter.java30
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java17
19 files changed, 222 insertions, 119 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java
index cedb159827..ccc19691b1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java
@@ -57,14 +57,12 @@ public class AutoCRLFInputStream extends InputStream {
this.detectBinary = detectBinary;
}
- /** {@inheritDoc} */
@Override
public int read() throws IOException {
final int read = read(single, 0, 1);
return read == 1 ? single[0] & 0xff : -1;
}
- /** {@inheritDoc} */
@Override
public int read(byte[] bs, int off, int len) throws IOException {
if (len == 0)
@@ -103,7 +101,6 @@ public class AutoCRLFInputStream extends InputStream {
return n;
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
in.close();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
index 305ccbd7e6..9fb316f28d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
@@ -65,14 +65,12 @@ public class AutoCRLFOutputStream extends OutputStream {
this.detectBinary = detectBinary;
}
- /** {@inheritDoc} */
@Override
public void write(int b) throws IOException {
onebytebuf[0] = (byte) b;
write(onebytebuf, 0, 1);
}
- /** {@inheritDoc} */
@Override
public void write(byte[] b) throws IOException {
int overflow = buffer(b, 0, b.length);
@@ -80,7 +78,6 @@ public class AutoCRLFOutputStream extends OutputStream {
write(b, b.length - overflow, overflow);
}
- /** {@inheritDoc} */
@Override
public void write(byte[] b, int startOff, int startLen)
throws IOException {
@@ -151,7 +148,6 @@ public class AutoCRLFOutputStream extends OutputStream {
write(binbuf, 0, cachedLen);
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
if (binbufcnt <= binbuf.length) {
@@ -161,7 +157,6 @@ public class AutoCRLFOutputStream extends OutputStream {
out.flush();
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
flush();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java
index 7db882c074..4b9706a3ce 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java
@@ -147,52 +147,12 @@ public class AutoLFInputStream extends InputStream {
&& flags.contains(StreamFlag.FOR_CHECKOUT);
}
- /**
- * Creates a new InputStream, wrapping the specified stream.
- *
- * @param in
- * raw input stream
- * @param detectBinary
- * whether binaries should be detected
- * @since 2.0
- * @deprecated since 5.9, use {@link #create(InputStream, StreamFlag...)}
- * instead
- */
- @Deprecated
- public AutoLFInputStream(InputStream in, boolean detectBinary) {
- this(in, detectBinary, false);
- }
-
- /**
- * Creates a new InputStream, wrapping the specified stream.
- *
- * @param in
- * raw input stream
- * @param detectBinary
- * whether binaries should be detected
- * @param abortIfBinary
- * throw an IOException if the file is binary
- * @since 3.3
- * @deprecated since 5.9, use {@link #create(InputStream, StreamFlag...)}
- * instead
- */
- @Deprecated
- public AutoLFInputStream(InputStream in, boolean detectBinary,
- boolean abortIfBinary) {
- this.in = in;
- this.detectBinary = detectBinary;
- this.abortIfBinary = abortIfBinary;
- this.forCheckout = false;
- }
-
- /** {@inheritDoc} */
@Override
public int read() throws IOException {
final int read = read(single, 0, 1);
return read == 1 ? single[0] & 0xff : -1;
}
- /** {@inheritDoc} */
@Override
public int read(byte[] bs, int off, int len)
throws IOException {
@@ -242,7 +202,6 @@ public class AutoLFInputStream extends InputStream {
return isBinary;
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
in.close();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
index a0e9fb68c5..e56991d43a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
@@ -69,14 +69,12 @@ public class AutoLFOutputStream extends OutputStream {
this.detectBinary = detectBinary;
}
- /** {@inheritDoc} */
@Override
public void write(int b) throws IOException {
onebytebuf[0] = (byte) b;
write(onebytebuf, 0, 1);
}
- /** {@inheritDoc} */
@Override
public void write(byte[] b) throws IOException {
int overflow = buffer(b, 0, b.length);
@@ -85,7 +83,6 @@ public class AutoLFOutputStream extends OutputStream {
}
}
- /** {@inheritDoc} */
@Override
public void write(byte[] b, int startOff, int startLen)
throws IOException {
@@ -164,7 +161,6 @@ public class AutoLFOutputStream extends OutputStream {
write(binbuf, 0, cachedLen);
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
if (binbufcnt <= binbuf.length) {
@@ -173,7 +169,6 @@ public class AutoLFOutputStream extends OutputStream {
out.flush();
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
flush();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/ByteBufferInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/ByteBufferInputStream.java
new file mode 100644
index 0000000000..804f7f860a
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/ByteBufferInputStream.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2023, SAP SE and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.util.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.InvalidMarkException;
+import java.util.Objects;
+
+import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.internal.JGitText;
+
+/**
+ * An {@link InputStream} backed by a {@link ByteBuffer}.
+ *
+ * @since 6.8
+ */
+public class ByteBufferInputStream extends InputStream {
+
+ private ByteBuffer buf;
+
+ /**
+ * Creates a {@link ByteBufferInputStream}
+ *
+ * @param buf
+ * the ByteBuffer backing the stream
+ */
+ public ByteBufferInputStream(@NonNull ByteBuffer buf) {
+ this.buf = buf;
+ }
+
+ @Override
+ public int read() throws IOException {
+ nullCheck();
+ if (buf.hasRemaining()) {
+ return buf.get() & 0xFF;
+ }
+ return -1;
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ nullCheck();
+ return read(b, 0, b.length);
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ nullCheck();
+ Objects.checkFromIndexSize(off, len, b.length);
+ if (len == 0) {
+ return 0;
+ }
+ int length = Math.min(buf.remaining(), len);
+ if (length == 0) {
+ return -1;
+ }
+ buf.get(b, off, length);
+ return length;
+ }
+
+ @Override
+ public byte[] readAllBytes() throws IOException {
+ return readNBytes(buf.remaining());
+ }
+
+ @Override
+ public byte[] readNBytes(int len) throws IOException {
+ int l = Math.min(len, buf.remaining());
+ byte[] b = new byte[l];
+ read(b);
+ return b;
+ }
+
+ @Override
+ public int readNBytes(byte[] b, int off, int len) throws IOException {
+ return read(b, off, len);
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ nullCheck();
+ if (n <= 0) {
+ return 0;
+ }
+ // ByteBuffer index has type int
+ int delta = n > Integer.MAX_VALUE ? buf.remaining()
+ : Math.min((int) n, buf.remaining());
+ buf.position(buf.position() + delta);
+ return delta;
+ }
+
+ @Override
+ public int available() throws IOException {
+ nullCheck();
+ return buf.remaining();
+ }
+
+ @Override
+ public void close() {
+ buf = null;
+ }
+
+ @Override
+ public synchronized void mark(int readlimit) {
+ buf.mark();
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ try {
+ buf.reset();
+ } catch (InvalidMarkException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public boolean markSupported() {
+ return true;
+ }
+
+ private void nullCheck() throws IOException {
+ if (buf == null) {
+ throw new IOException(JGitText.get().inputStreamClosed);
+ }
+ }
+}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/CountingOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/CountingOutputStream.java
index 782f3f4ca6..d0049d29de 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/CountingOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/CountingOutputStream.java
@@ -39,27 +39,23 @@ public class CountingOutputStream extends OutputStream {
return cnt;
}
- /** {@inheritDoc} */
@Override
public void write(int val) throws IOException {
out.write(val);
cnt++;
}
- /** {@inheritDoc} */
@Override
public void write(byte[] buf, int off, int len) throws IOException {
out.write(buf, off, len);
cnt += len;
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
out.flush();
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
out.close();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/DisabledOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/DisabledOutputStream.java
index f1bfbe29a5..03c25bb702 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/DisabledOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/DisabledOutputStream.java
@@ -27,7 +27,6 @@ public final class DisabledOutputStream extends OutputStream {
// more than one instance from being created.
}
- /** {@inheritDoc} */
@Override
public void write(int b) throws IOException {
// We shouldn't be writing output at this stage, there
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java
index 7e46afbc4b..888b8fbb09 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java
@@ -104,10 +104,20 @@ public final class InterruptTimer {
*/
public void terminate() {
state.terminate();
+ boolean interrupted = false;
try {
- thread.join();
- } catch (InterruptedException e) {
- //
+ while (true) {
+ try {
+ thread.join();
+ return;
+ } catch (InterruptedException e) {
+ interrupted = true;
+ }
+ }
+ } finally {
+ if (interrupted) {
+ Thread.currentThread().interrupt();
+ }
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java
index 2bbdbefd38..1faf6ea9aa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java
@@ -58,13 +58,11 @@ public class IsolatedOutputStream extends OutputStream {
new ArrayBlockingQueue<>(1), new NamedThreadFactory());
}
- /** {@inheritDoc} */
@Override
public void write(int ch) throws IOException {
write(new byte[] { (byte) ch }, 0, 1);
}
- /** {@inheritDoc} */
@Override
public void write(byte[] buf, int pos, int cnt)
throws IOException {
@@ -75,7 +73,6 @@ public class IsolatedOutputStream extends OutputStream {
});
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
checkClosed();
@@ -85,7 +82,6 @@ public class IsolatedOutputStream extends OutputStream {
});
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
if (!copier.isShutdown()) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/LimitedInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/LimitedInputStream.java
index 88006242d9..681a52988e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/LimitedInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/LimitedInputStream.java
@@ -47,21 +47,18 @@ public abstract class LimitedInputStream extends FilterInputStream {
this.limit = limit;
}
- /** {@inheritDoc} */
@Override
public int available() throws IOException {
return (int) Math.min(in.available(), left);
}
// it's okay to mark even if mark isn't supported, as reset won't work
- /** {@inheritDoc} */
@Override
public synchronized void mark(int readLimit) {
in.mark(readLimit);
mark = left;
}
- /** {@inheritDoc} */
@Override
public int read() throws IOException {
if (left == 0) {
@@ -78,7 +75,6 @@ public abstract class LimitedInputStream extends FilterInputStream {
return result;
}
- /** {@inheritDoc} */
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (left == 0) {
@@ -96,7 +92,6 @@ public abstract class LimitedInputStream extends FilterInputStream {
return result;
}
- /** {@inheritDoc} */
@Override
public synchronized void reset() throws IOException {
if (!in.markSupported())
@@ -109,7 +104,6 @@ public abstract class LimitedInputStream extends FilterInputStream {
left = mark;
}
- /** {@inheritDoc} */
@Override
public long skip(long n) throws IOException {
n = Math.min(n, left);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java
index 2637766153..8d5b8fdcba 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java
@@ -51,7 +51,6 @@ public class MessageWriter extends Writer {
enc = new OutputStreamWriter(getRawStream(), UTF_8);
}
- /** {@inheritDoc} */
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
synchronized (buf) {
@@ -71,20 +70,17 @@ public class MessageWriter extends Writer {
return buf;
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
// Do nothing, we are buffered with no resources.
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
// Do nothing, we are buffered with no resources.
}
/** @return string version of all buffered data. */
- /** {@inheritDoc} */
@Override
public String toString() {
return RawParseUtils.decode(buf.toByteArray());
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SilentInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SilentInputStream.java
new file mode 100644
index 0000000000..8c2c61a434
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SilentInputStream.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2025 Thomas Wolf <twolf@apache.org> and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.util.io;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An {@link InputStream} that swallows exceptions on {@link #close()}.
+ *
+ * @since 7.4
+ */
+public class SilentInputStream extends FilterInputStream {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SilentInputStream.class);
+
+ /**
+ * Wraps an existing {@link InputStream}.
+ *
+ * @param in
+ * {@link InputStream} to wrap
+ */
+ public SilentInputStream(InputStream in) {
+ super(in);
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ super.close();
+ } catch (IOException e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Exception ignored while closing input stream", e); //$NON-NLS-1$
+ }
+ }
+ }
+}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java
index c0724e43f2..ed412fa6f5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java
@@ -67,7 +67,6 @@ public class StreamCopyThread extends Thread {
}
}
- /** {@inheritDoc} */
@Override
public void run() {
try {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java
index 56d0169f7d..96376bfc6a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java
@@ -46,7 +46,6 @@ public class TeeInputStream extends InputStream {
this.dst = dst;
}
- /** {@inheritDoc} */
@Override
public int read() throws IOException {
byte[] b = skipBuffer();
@@ -54,7 +53,6 @@ public class TeeInputStream extends InputStream {
return n == 1 ? b[0] & 0xff : -1;
}
- /** {@inheritDoc} */
@Override
public long skip(long count) throws IOException {
long skipped = 0;
@@ -71,7 +69,6 @@ public class TeeInputStream extends InputStream {
return skipped;
}
- /** {@inheritDoc} */
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (len == 0)
@@ -83,7 +80,6 @@ public class TeeInputStream extends InputStream {
return n;
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
byte[] b = skipBuffer();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeOutputStream.java
index e6fdd709b2..ab084a66f2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeOutputStream.java
@@ -34,35 +34,30 @@ public class TeeOutputStream extends OutputStream {
this.stream2 = stream2;
}
- /** {@inheritDoc} */
@Override
public void write(byte[] buf) throws IOException {
this.stream1.write(buf);
this.stream2.write(buf);
}
- /** {@inheritDoc} */
@Override
public void write(byte[] buf, int off, int len) throws IOException {
this.stream1.write(buf, off, len);
this.stream2.write(buf, off, len);
}
- /** {@inheritDoc} */
@Override
public void write(int b) throws IOException {
this.stream1.write(b);
this.stream2.write(b);
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
this.stream1.flush();
this.stream2.flush();
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
try {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/ThrowingPrintWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/ThrowingPrintWriter.java
index 3bc92d5bcd..13982b133c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/ThrowingPrintWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/ThrowingPrintWriter.java
@@ -11,8 +11,6 @@ package org.eclipse.jgit.util.io;
import java.io.IOException;
import java.io.Writer;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import org.eclipse.jgit.util.SystemReader;
@@ -35,25 +33,19 @@ public class ThrowingPrintWriter extends Writer {
*/
public ThrowingPrintWriter(Writer out) {
this.out = out;
- LF = AccessController
- .doPrivileged((PrivilegedAction<String>) () -> SystemReader
- .getInstance().getProperty("line.separator") //$NON-NLS-1$
- );
+ LF = SystemReader.getInstance().getProperty("line.separator"); //$NON-NLS-1$
}
- /** {@inheritDoc} */
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
out.write(cbuf, off, len);
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
out.flush();
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
out.close();
@@ -62,8 +54,10 @@ public class ThrowingPrintWriter extends Writer {
/**
* Print a string and terminate with a line feed.
*
- * @param s a {@link java.lang.String} object.
+ * @param s
+ * a {@link java.lang.String} object.
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void println(String s) throws IOException {
print(s + LF);
@@ -73,6 +67,7 @@ public class ThrowingPrintWriter extends Writer {
* Print a platform dependent new line
*
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void println() throws IOException {
print(LF);
@@ -81,8 +76,10 @@ public class ThrowingPrintWriter extends Writer {
/**
* Print a char
*
- * @param value a char.
+ * @param value
+ * a char.
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void print(char value) throws IOException {
print(String.valueOf(value));
@@ -94,6 +91,7 @@ public class ThrowingPrintWriter extends Writer {
* @param value
* an int.
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void print(int value) throws IOException {
print(String.valueOf(value));
@@ -102,8 +100,10 @@ public class ThrowingPrintWriter extends Writer {
/**
* Print a long as string
*
- * @param value a long.
+ * @param value
+ * a long.
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void print(long value) throws IOException {
print(String.valueOf(value));
@@ -112,8 +112,10 @@ public class ThrowingPrintWriter extends Writer {
/**
* Print a short as string
*
- * @param value a short.
+ * @param value
+ * a short.
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void print(short value) throws IOException {
print(String.valueOf(value));
@@ -128,6 +130,7 @@ public class ThrowingPrintWriter extends Writer {
* @param args
* objects.
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void format(String fmt, Object... args) throws IOException {
print(String.format(fmt, args));
@@ -139,6 +142,7 @@ public class ThrowingPrintWriter extends Writer {
* @param any
* an object.
* @throws java.io.IOException
+ * if an IO error occurred
*/
public void print(Object any) throws IOException {
out.write(String.valueOf(any));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java
index 1947b3bf04..4d9f83d233 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java
@@ -63,7 +63,6 @@ public class TimeoutInputStream extends FilterInputStream {
timeout = millis;
}
- /** {@inheritDoc} */
@Override
public int read() throws IOException {
try {
@@ -76,13 +75,11 @@ public class TimeoutInputStream extends FilterInputStream {
}
}
- /** {@inheritDoc} */
@Override
public int read(byte[] buf) throws IOException {
return read(buf, 0, buf.length);
}
- /** {@inheritDoc} */
@Override
public int read(byte[] buf, int off, int cnt) throws IOException {
try {
@@ -95,7 +92,6 @@ public class TimeoutInputStream extends FilterInputStream {
}
}
- /** {@inheritDoc} */
@Override
public long skip(long cnt) throws IOException {
try {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java
index 3fbf6ffdcb..afd798a1a2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java
@@ -65,7 +65,6 @@ public class TimeoutOutputStream extends OutputStream {
timeout = millis;
}
- /** {@inheritDoc} */
@Override
public void write(int b) throws IOException {
try {
@@ -78,13 +77,11 @@ public class TimeoutOutputStream extends OutputStream {
}
}
- /** {@inheritDoc} */
@Override
public void write(byte[] buf) throws IOException {
write(buf, 0, buf.length);
}
- /** {@inheritDoc} */
@Override
public void write(byte[] buf, int off, int len) throws IOException {
try {
@@ -97,7 +94,6 @@ public class TimeoutOutputStream extends OutputStream {
}
}
- /** {@inheritDoc} */
@Override
public void flush() throws IOException {
try {
@@ -110,7 +106,6 @@ public class TimeoutOutputStream extends OutputStream {
}
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
try {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java
index 459888190f..7e950f6529 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java
@@ -12,8 +12,8 @@ package org.eclipse.jgit.util.io;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.ArrayDeque;
+import java.util.Deque;
/**
* An InputStream which reads from one or more InputStreams.
@@ -34,7 +34,7 @@ public class UnionInputStream extends InputStream {
}
};
- private final LinkedList<InputStream> streams = new LinkedList<>();
+ private final Deque<InputStream> streams = new ArrayDeque<>();
/**
* Create an empty InputStream that is currently at EOF state.
@@ -91,7 +91,6 @@ public class UnionInputStream extends InputStream {
return streams.isEmpty();
}
- /** {@inheritDoc} */
@Override
public int read() throws IOException {
for (;;) {
@@ -106,7 +105,6 @@ public class UnionInputStream extends InputStream {
}
}
- /** {@inheritDoc} */
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (len == 0)
@@ -123,13 +121,11 @@ public class UnionInputStream extends InputStream {
}
}
- /** {@inheritDoc} */
@Override
public int available() throws IOException {
return head().available();
}
- /** {@inheritDoc} */
@Override
public long skip(long count) throws IOException {
long skipped = 0;
@@ -163,19 +159,18 @@ public class UnionInputStream extends InputStream {
return skipped;
}
- /** {@inheritDoc} */
@Override
public void close() throws IOException {
IOException err = null;
- for (Iterator<InputStream> i = streams.iterator(); i.hasNext();) {
+ for (InputStream stream : streams) {
try {
- i.next().close();
+ stream.close();
} catch (IOException closeError) {
err = closeError;
}
- i.remove();
}
+ streams.clear();
if (err != null)
throw err;