Top Description Fields Constructors Methods
org.eclipse.jgit.transport

public Class PacketLineOut

extends Object
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8

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

Modifier and TypeField and Description
private boolean
private static final byte[]
private final byte[]
private static final Logger
private final boolean
private final OutputStream
private boolean

Constructor Summary

AccessConstructor and Description
public
PacketLineOut(OutputStream
stream.
outputStream
)

Create a new packet line writer.

public
PacketLineOut(OutputStream
stream.
outputStream
,
boolean
false to suppress all logging; true to log normally
enableLogging
)

Create a new packet line writer that potentially doesn't log.

Method Summary

Modifier and TypeMethod and Description
public void
end()

Write a packet end marker, sometimes referred to as a flush command.

public void
flush()

Flush the underlying OutputStream.

private void
formatLength(int w)

pack-priv static void
formatLength(byte[] lenbuffer, int w)

public boolean

Returns:

whether to add a sideband designator to each non-flush and non-delim packet
isUsingSideband
()

Whether is using sideband

public void
setFlushOnEnd(boolean
if true, a flush-pkt written during end() also flushes the underlying stream.
flushOnEnd
)

Set the flush behavior during end().

public void
setUsingSideband(boolean
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.
value
)

Set whether to use sideband

public void
writeDelim()

Write a packet delim marker (0001).

public void
writePacket(byte[]
the packet to write; the length of the packet is equal to the size of the byte array.
packet
)

Write a binary packet to the stream.

public void
writePacket(byte[]
the packet to write
buf
,
int
first index within buf.
pos
,
int
number of bytes to write.
len
)

Write a binary packet to the stream.

public void
writeString(String
string to write.
s
)

Write a UTF-8 encoded string as a single length-delimited packet.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

flushOnEndback to summary
private boolean flushOnEnd
hexcharback to summary
private static final byte[] hexchar
lenbufferback to summary
private final byte[] lenbuffer
logback to summary
private static final Logger log
logEnabledback to summary
private final boolean logEnabled
outback to summary
private final OutputStream out
usingSidebandback to summary
private boolean usingSideband

Constructor Detail

PacketLineOutback to summary
public PacketLineOut(OutputStream outputStream)

Create a new packet line writer.

Parameters
outputStream:OutputStream

stream.

PacketLineOutback to summary
public PacketLineOut(OutputStream outputStream, boolean enableLogging)

Create a new packet line writer that potentially doesn't log.

Parameters
outputStream:OutputStream

stream.

enableLogging:boolean

false to suppress all logging; true to log normally

Since
5.11

Method Detail

endback to summary
public void end() throws IOException

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.

Exceptions
IOException:
the end marker could not be written, the stream is corrupted as the end marker may have been only partially written.
flushback to summary
public void flush() throws IOException

Flush the underlying OutputStream.

Performs a flush on the underlying OutputStream to ensure the peer will receive all data written thus far.

Exceptions
IOException:
the underlying stream failed to flush.
formatLengthback to summary
private void formatLength(int w)
formatLengthback to summary
pack-priv static void formatLength(byte[] lenbuffer, int w)
isUsingSidebandback to summary
public boolean isUsingSideband()

Whether is using sideband

Returns:boolean

whether to add a sideband designator to each non-flush and non-delim packet

Since
5.5
See Also
setUsingSideband
setFlushOnEndback to summary
public void setFlushOnEnd(boolean flushOnEnd)

Set the flush behavior during end().

Parameters
flushOnEnd:boolean

if true, a flush-pkt written during end() also flushes the underlying stream.

setUsingSidebandback to summary
public void setUsingSideband(boolean value)

Set whether to use sideband

Parameters
value:boolean

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
writeDelimback to summary
public void writeDelim() throws IOException

Write a packet delim marker (0001).

Exceptions
IOException:
the marker could not be written, the stream is corrupted as the marker may have been only partially written.
Since
5.0
writePacketback to summary
public void writePacket(byte[] packet) throws IOException

Write a binary packet to the stream.

Parameters
packet:byte[]

the packet to write; the length of the packet is equal to the size of the byte array.

Exceptions
IOException:
the packet could not be written, the stream is corrupted as the packet may have been only partially written.
writePacketback to summary
public void writePacket(byte[] buf, int pos, int len) throws IOException

Write a binary packet to the stream.

Parameters
buf:byte[]

the packet to write

pos:int

first index within buf.

len:int

number of bytes to write.

Exceptions
IOException:
the packet could not be written, the stream is corrupted as the packet may have been only partially written.
Since
4.5
writeStringback to summary
public void writeString(String s) throws IOException

Write a UTF-8 encoded string as a single length-delimited packet.

Parameters
s:String

string to write.

Exceptions
IOException:
the packet could not be written, the stream is corrupted as the packet may have been only partially written.