Package com.martiansoftware.nailgun
Class NGOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.DataOutputStream
com.martiansoftware.nailgun.NGOutputStream
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
Wraps an OutputStream to send writes in NailGun chunks. Because
multiple NGOutputStreams wrap the same OutputStream (that is,
the OutputStream obtained from the Socket connection with
the client), writes are synchronized on the underlying OutputStream.
If this were not the case, write interleaving could completely
break the NailGun protocol.
-
Field Summary
FieldsFields inherited from class java.io.DataOutputStream
writtenFields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionNGOutputStream(OutputStream out, byte streamCode) Creates a new NGOutputStream wrapping the specified OutputStream and using the specified Nailgun chunk code. -
Method Summary
Methods inherited from class java.io.DataOutputStream
size, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Field Details
-
lock
-
streamCode
private byte streamCode -
closed
private boolean closed
-
-
Constructor Details
-
NGOutputStream
Creates a new NGOutputStream wrapping the specified OutputStream and using the specified Nailgun chunk code.- Parameters:
out- the OutputStream to wrapstreamCode- the NailGun chunk code associated with this stream (i.e., '1' for stdout, '2' for stderr).
-
-
Method Details
-
write
- Specified by:
writein interfaceDataOutput- Overrides:
writein classFilterOutputStream- Throws:
IOException- See Also:
-
write
- Specified by:
writein interfaceDataOutput- Overrides:
writein classDataOutputStream- Throws:
IOException- See Also:
-
write
- Specified by:
writein interfaceDataOutput- Overrides:
writein classDataOutputStream- Throws:
IOException- See Also:
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException- See Also:
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classDataOutputStream- Throws:
IOException- See Also:
-
throwIfClosed
Check if stream is closed and throw an IOException if yes. In the case of a public operation is being performed while the stream is already closed throws an IOException.- Throws:
IOException
-