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.OutputStream
OutputStream 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
BufferedOutputStream
using 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 class
IsolatedOutputStream.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 void
checkClosed()
private static void
checkedGet(java.util.concurrent.Future<java.lang.Void> future)
private void
cleanClose()
void
close()
private void
dirtyClose()
private void
execute(java.util.concurrent.Callable<java.lang.Void> task)
void
flush()
private static java.io.InterruptedIOException
interrupted(java.lang.InterruptedException c)
private boolean
tryCleanClose()
void
write(byte[] buf, int pos, int cnt)
void
write(int ch)
-
-
-
Method Detail
-
write
public void write(int ch) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] buf, int pos, int cnt) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in 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)
-
-