Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util.io

public Class IsolatedOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.IOException, .InterruptedIOException, .OutputStream, java.util.concurrent.ArrayBlockingQueue, .Callable, .ExecutionException, .ExecutorService, .Future, .RejectedExecutionException, .ThreadFactory, .ThreadPoolExecutor, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicInteger, org.eclipse.jgit.internal.JGitText

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 and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final ExecutorService
private final OutputStream
private Future<Void>

Constructor Summary

AccessConstructor and Description
public
IsolatedOutputStream(OutputStream
stream to send all writes to.
out
)

Wraps an OutputStream.

Method Summary

Modifier and TypeMethod and Description
private void
private static void
private void
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

private void
private void
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.

private static InterruptedIOException
private boolean
public void
write(int
the byte.
ch
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

public void
write(byte[]
the data.
buf
,
int
the start offset in the data.
pos
,
int
the number of bytes to write.
cnt
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Inherited from java.io.OutputStream:
nullOutputStreamwrite

Field Detail

copierback to summary
private final ExecutorService copier
dstback to summary
private final OutputStream dst
pendingback to summary
private Future<Void> pending

Constructor Detail

IsolatedOutputStreamback to summary
public IsolatedOutputStream(OutputStream out)

Wraps an OutputStream.

Parameters
out:OutputStream

stream to send all writes to.

Method Detail

checkClosedback to summary
private void checkClosed() throws IOException
checkedGetback to summary
private static void checkedGet(Future<Void> future) throws IOException
cleanCloseback to summary
private void cleanClose() throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
dirtyCloseback to summary
private void dirtyClose() throws IOException
executeback to summary
private void execute(Callable<Void> task) throws IOException
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
interruptedback to summary
private static InterruptedIOException interrupted(InterruptedException c)
tryCleanCloseback to summary
private boolean tryCleanClose()
writeback to summary
public void write(int ch) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
ch:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] buf, int pos, int cnt) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
buf:byte[]

the data.

pos:int

the start offset in the data.

cnt:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
org.eclipse.jgit.util.io back to summary

private Class IsolatedOutputStream.NamedThreadFactory

extends Object
implements ThreadFactory
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.util.io.IsolatedOutputStream.NamedThreadFactory
All Implemented Interfaces
java.util.concurrent.ThreadFactory

Field Summary

Modifier and TypeField and Description
private static final AtomicInteger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Thread
newThread(Runnable
a runnable to be executed by new thread instance
r
)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cntback to summary
private static final AtomicInteger cnt

Constructor Detail

NamedThreadFactoryback to summary
private NamedThreadFactory()

Method Detail

newThreadback to summary
public Thread newThread(Runnable r)

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Parameters
r:Runnable

a runnable to be executed by new thread instance

Returns:Thread

constructed thread, or null if the request to create a thread is rejected

Annotations
@Override