Package org.eclipse.jgit.transport
Class PacketLineOut
java.lang.Object
org.eclipse.jgit.transport.PacketLineOut
Write Git style pkt-line formatting to an output stream.
This class is not thread safe and may issue multiple writes to the underlying stream for each method call made.
This class performs no buffering on its own. This makes it suitable to interleave writes performed by this class with writes performed directly against the underlying OutputStream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private static final byte[]
private final byte[]
private static final org.slf4j.Logger
private final boolean
private final OutputStream
private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionPacketLineOut
(OutputStream outputStream) Create a new packet line writer.PacketLineOut
(OutputStream outputStream, boolean enableLogging) Create a new packet line writer that potentially doesn't log. -
Method Summary
Modifier and TypeMethodDescriptionvoid
end()
Write a packet end marker, sometimes referred to as a flush command.void
flush()
Flush the underlying OutputStream.(package private) static void
formatLength
(byte[] lenbuffer, int w) private void
formatLength
(int w) boolean
void
setFlushOnEnd
(boolean flushOnEnd) Set the flush behavior duringend()
.void
setUsingSideband
(boolean value) void
Write a packet delim marker (0001).void
writePacket
(byte[] packet) Write a binary packet to the stream.void
writePacket
(byte[] buf, int pos, int len) Write a binary packet to the stream.void
Write a UTF-8 encoded string as a single length-delimited packet.
-
Field Details
-
log
private static final org.slf4j.Logger log -
out
-
lenbuffer
private final byte[] lenbuffer -
logEnabled
private final boolean logEnabled -
flushOnEnd
private boolean flushOnEnd -
usingSideband
private boolean usingSideband -
hexchar
private static final byte[] hexchar
-
-
Constructor Details
-
PacketLineOut
Create a new packet line writer.- Parameters:
outputStream
- stream.
-
PacketLineOut
Create a new packet line writer that potentially doesn't log.- Parameters:
outputStream
- stream.enableLogging
-false
to suppress all logging;true
to log normally- Since:
- 5.11
-
-
Method Details
-
setFlushOnEnd
public void setFlushOnEnd(boolean flushOnEnd) Set the flush behavior duringend()
.- Parameters:
flushOnEnd
- if true, a flush-pkt written duringend()
also flushes the underlying stream.
-
isUsingSideband
public boolean isUsingSideband()- Returns:
- whether to add a sideband designator to each non-flush and non-delim packet
- Since:
- 5.5
- See Also:
-
setUsingSideband
public void setUsingSideband(boolean value) - Parameters:
value
- If true, when writing packet lines, add, as the first byte, a sideband designator to each non-flush and non-delim packet. See pack-protocol.txt and protocol-v2.txt from the Git project for more information, specifically the "side-band" and "sideband-all" sections.- Since:
- 5.5
-
writeString
Write a UTF-8 encoded string as a single length-delimited packet.- Parameters:
s
- string to write.- Throws:
IOException
- the packet could not be written, the stream is corrupted as the packet may have been only partially written.
-
writePacket
Write a binary packet to the stream.- Parameters:
packet
- the packet to write; the length of the packet is equal to the size of the byte array.- Throws:
IOException
- the packet could not be written, the stream is corrupted as the packet may have been only partially written.
-
writePacket
Write a binary packet to the stream.- Parameters:
buf
- the packet to writepos
- first index withinbuf
.len
- number of bytes to write.- Throws:
IOException
- the packet could not be written, the stream is corrupted as the packet may have been only partially written.- Since:
- 4.5
-
writeDelim
Write a packet delim marker (0001).- Throws:
IOException
- the marker could not be written, the stream is corrupted as the marker may have been only partially written.- Since:
- 5.0
-
end
Write a packet end marker, sometimes referred to as a flush command.Technically this is a magical packet type which can be detected separately from an empty string or an empty packet.
Implicitly performs a flush on the underlying OutputStream to ensure the peer will receive all data written thus far.
- Throws:
IOException
- the end marker could not be written, the stream is corrupted as the end marker may have been only partially written.
-
flush
Flush the underlying OutputStream.Performs a flush on the underlying OutputStream to ensure the peer will receive all data written thus far.
- Throws:
IOException
- the underlying stream failed to flush.
-
formatLength
private void formatLength(int w) -
formatLength
static void formatLength(byte[] lenbuffer, int w)
-