Package org.eclipse.jgit.util.io
Class IsolatedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.eclipse.jgit.util.io.IsolatedOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class IsolatedOutputStream extends java.io.OutputStreamOutputStream isolated from interrupts.Wraps an OutputStream to prevent interrupts during writes from being made visible to that stream instance. This works around buggy or difficult OutputStream implementations like JSch that cannot gracefully handle an interrupt during write.
Every write (or flush) requires a context switch to another thread. Callers should wrap this stream with
BufferedOutputStreamusing a suitable buffer size to amortize the cost of context switches.- Since:
- 4.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classIsolatedOutputStream.NamedThreadFactory
-
Constructor Summary
Constructors Constructor Description IsolatedOutputStream(java.io.OutputStream out)Wraps an OutputStream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckClosed()private static voidcheckedGet(java.util.concurrent.Future<java.lang.Void> future)private voidcleanClose()voidclose()private voiddirtyClose()private voidexecute(java.util.concurrent.Callable<java.lang.Void> task)voidflush()private static java.io.InterruptedIOExceptioninterrupted(java.lang.InterruptedException c)private booleantryCleanClose()voidwrite(byte[] buf, int pos, int cnt)voidwrite(int ch)
-
-
-
Method Detail
-
write
public void write(int ch) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] buf, int pos, int cnt) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
tryCleanClose
private boolean tryCleanClose()
-
cleanClose
private void cleanClose() throws java.io.IOException- Throws:
java.io.IOException
-
dirtyClose
private void dirtyClose() throws java.io.IOException- Throws:
java.io.IOException
-
checkClosed
private void checkClosed() throws java.io.IOException- Throws:
java.io.IOException
-
execute
private void execute(java.util.concurrent.Callable<java.lang.Void> task) throws java.io.IOException- Throws:
java.io.IOException
-
checkedGet
private static void checkedGet(java.util.concurrent.Future<java.lang.Void> future) throws java.io.IOException- Throws:
java.io.IOException
-
interrupted
private static java.io.InterruptedIOException interrupted(java.lang.InterruptedException c)
-
-