org.tmatesoft.svn.core.io.diff
public class SVNDiffWindow extends Object
Instructions are not immediately contained in a window. A diff window provides an iterator that reads and constructs one SVNDiffInstruction from provided raw bytes per one iteration. There is even an ability to use a single SVNDiffInstruction object for read and decoded instructions: for subsequent iterations an iterator simply uses the same instruction object to return as a newly read and decoded instruction.
Version: 1.1.1
See Also: SVNDiffInstruction
Field Summary | |
---|---|
static SVNDiffWindow | EMPTY
An empty window (in particular, its instructions length = 0). |
static byte[] | SVN1_HEADER
Bytes of the delta header of a compressed diff window. |
static byte[] | SVN_HEADER
Bytes of the delta header of an uncompressed diff window. |
Constructor Summary | |
---|---|
SVNDiffWindow(long sourceViewOffset, int sourceViewLength, int targetViewLength, int instructionsLength, int newDataLength)
Constructs an SVNDiffWindow object. |
Method Summary | |
---|---|
void | apply(SVNDiffWindowApplyBaton applyBaton)
Applies this window's instructions. |
int | apply(byte[] sourceBuffer, byte[] targetBuffer)
Applies this window's instructions provided source and target view buffers.
|
SVNDiffWindow | clone(ByteBuffer targetData)
Creates an exact copy of this window object.
|
int | getDataLength()
Returns the total amount of new data and instruction bytes.
|
int | getInstructionsCount()
Returns the amount of instructions of this window object.
|
int | getInstructionsLength()
Returns the length of instructions in bytes.
|
int | getNewDataLength()
Returns the number of new data bytes to copy to the target view.
|
int | getSourceViewLength()
Returns the number of bytes to copy from the source view to the target one.
|
long | getSourceViewOffset()
Returns the source view offset.
|
int | getTargetViewLength()
Returns the length in bytes of the target view. |
boolean | hasCopyFromSourceInstructions()
Tells whether this window contains any copy-from-source
instructions.
|
boolean | hasInstructions()
Tells if this window is not empty, i.e. has got any instructions.
|
Iterator | instructions()
Returns an iterator to read instructions in series.
|
Iterator | instructions(boolean template)
Returns an iterator to read instructions in series.
|
SVNDiffInstruction[] | loadDiffInstructions(SVNDiffInstruction[] target)
Returns an array of instructions of this window.
|
void | setData(ByteBuffer buffer)
Sets a byte buffer containing instruction and new data bytes
of this window.
|
String | toString()
Gives a string representation of this object.
|
void | writeNewData(ByteBuffer target, int offset, int length)
Fills a target buffer with the specified number of new data bytes
of this window object taken at the specified offset.
|
void | writeTo(OutputStream os, boolean writeHeader)
Writes this window object to the provided stream.
|
void | writeTo(OutputStream os, boolean writeHeader, boolean compress)
Formats and writes this window bytes to the specified output stream.
|
Since: 1.1, new in Subversion 1.4
Parameters: sourceViewOffset an offset in the source view sourceViewLength a number of bytes to read from the source view targetViewLength a length in bytes of the target view it must have after copying bytes instructionsLength a number of instructions bytes newDataLength a number of bytes of new data
See Also: SVNDiffInstruction
applyBaton
.
If this window has got any COPY_FROM_SOURCE instructions, then:
applyBaton
to the baton's inner source buffer.
COPY_FROM_SOURCE instructions of this window are
relative to the bounds of that source buffer (source view, in other words).
applyBaton
is supplied with an MD5 digest, updates it with those bytes
in the target buffer. So, after instructions applying completes, it will be the checksum for
the full text expanded.
COPY_FROM_NEW_DATA instructions rule to copy bytes from
the instructions & new data buffer provided to this window object via a call to the
setData()
method.
COPY_FROM_TARGET instructions are relative to the bounds of the target buffer.
Parameters: applyBaton a baton that provides the source and target views as well as holds the source and targed streams
Throws: SVNException
See Also: (byte[], byte[])
If this window has got any COPY_FROM_SOURCE instructions, then
appropriate bytes described by such an instruction are copied from the sourceBuffer
to the targetBuffer
.
COPY_FROM_NEW_DATA instructions rule to copy bytes from
the instructions & new data buffer provided to this window object via a call to the
setData()
method.
COPY_FROM_TARGET instructions are relative to the bounds of
the targetBuffer
itself.
Parameters: sourceBuffer a buffer containing a source view targetBuffer a buffer to get a target view
Returns: the size of the resultant target view
See Also: apply
targetData
is written instruction & new data bytes and
then is set to a new window object via a call to its setData()
method.
Parameters: targetData a byte buffer to receive a copy of this wondow data
Returns: a new window object that is an exact copy of this one
Returns: new data length + instructions length
Returns: a total number of instructions
Returns: a number of instructions bytes
Returns: a number of new data bytes
Returns: a number of source bytes to copy
Returns: an offset in the source from where the source bytes must be copied
Returns: a length in bytes of the target view
Returns: true if this window has got at least one COPY_FROM_SOURCE instruction
Returns: true if has instructions, false if has not
next()
method
are separate SVNDiffInstruction objects.
Instructions as well as new data are read from a byte
buffer that is passed to this window object via the
setData()
method.
A call to this routine is equivalent to a call
instructions(false)
.
Returns: an instructions iterator
See Also: SVNDiffWindow SVNDiffInstruction
If template
is true
then each instruction returned by the iterator is actually the
same SVNDiffInstruction object, but with proper options.
This prevents from allocating new memory.
On the other hand, if template
is false
then the iterator returns a new allocated SVNDiffInstruction object per
each instruction read and decoded.
Instructions as well as new data are read from a byte buffer that is
passed to this window object via the
setData()
method.
Parameters: template to use a single/multiple instruction objects
Returns: an instructions iterator
See Also: instructions SVNDiffInstruction
If target
is large enough to receive all instruction
objects, then it's simply filled up to the end of instructions.
However if it's not, it will be expanded to receive all instructions.
Parameters: target an instructions receiver
Returns: an array containing all instructions
Instructions will go before new data within the buffer and should start
at buffer.position() + buffer.arrayOffset()
.
Applying a diff window prior to setting instruction and new data bytes may cause a NPE.
Parameters: buffer an input data buffer
Returns: a string representation of this object
Parameters: target a buffer to copy to offset an offset relative to the position of the first new data byte of this window object length a number of new data bytes to copy
If writeHeader
is true
then writes SVN_HEADER bytes also.
Parameters: os an output stream to write to writeHeader controls whether the header should be written or not
Throws: IOException if an I/O error occurs
Parameters: os an output stream to write the window to writeHeader if true a window
header will be also written compress if true writes
compressed window bytes using SVN1_HEADER
to indicate that (if writeHeader
is
true), otherwise
non-compressed window is written with SVN_HEADER
(again if writeHeader
is true)
Throws: IOException
Since: 1.1