org.tmatesoft.svn.core.io.diff
Class SVNDiffWindow
public class SVNDiffWindow
The
SVNDiffWindow class represents a diff window that
contains instructions and new data of a delta to apply to a file.
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.
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.
|
SVNDiffWindow(long sourceViewOffset, int sourceViewLength, int targetViewLength, int instructionsLength, int newDataLength)- Constructs an SVNDiffWindow object.
|
int | apply(byte[] sourceBuffer, byte[] targetBuffer)- Applies this window's instructions provided source and target view buffers.
|
void | apply(SVNDiffWindowApplyBaton applyBaton)- Applies this window's instructions.
|
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.
|
EMPTY
public static final SVNDiffWindow EMPTY
An empty window (in particular, its instructions length = 0). Corresponds
to the case of an empty delta, so, it's passed to a delta consumer to
create an empty file.
SVN1_HEADER
public static final byte[] SVN1_HEADER
Bytes of the delta header of a compressed diff window.
- 1.1, new in Subversion 1.4
SVN_HEADER
public static final byte[] SVN_HEADER
Bytes of the delta header of an uncompressed diff window.
SVNDiffWindow
public SVNDiffWindow(long sourceViewOffset,
int sourceViewLength,
int targetViewLength,
int instructionsLength,
int newDataLength) Constructs an SVNDiffWindow object. This constructor is
used when bytes of instructions are not decoded and converted to
SVNDiffInstruction objects yet, but are kept elsewhere
along with new data.
sourceViewOffset - an offset in the source viewsourceViewLength - a number of bytes to read from the
source viewtargetViewLength - a length in bytes of the target view
it must have after copying bytesinstructionsLength - a number of instructions bytesnewDataLength - a number of bytes of new data
apply
public int apply(byte[] sourceBuffer,
byte[] targetBuffer)sourceBuffer - a buffer containing a source viewtargetBuffer - a buffer to get a target view
- the size of the resultant target view
apply
public void apply(SVNDiffWindowApplyBaton applyBaton)
throws SVNException Applies this window's instructions. The source and target streams
are provided by
applyBaton.
If this window has got any
SVNDiffInstruction.COPY_FROM_SOURCE instructions, then:
- At first copies a source view from the source stream
of
applyBaton to the baton's inner source buffer.
SVNDiffInstruction.COPY_FROM_SOURCE instructions of this window are
relative to the bounds of that source buffer (source view, in other words).
- Second, according to instructions, copies source bytes from the source buffer
to the baton's target buffer (or target view, in other words).
- Then, if
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.
- The last step - appends the target buffer bytes to the baton's
target stream.
SVNDiffInstruction.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.
SVNDiffInstruction.COPY_FROM_TARGET instructions are relative to the bounds of
the target buffer.
applyBaton - a baton that provides the source and target
views as well as holds the source and targed
streams
clone
public SVNDiffWindow clone(ByteBuffer targetData)
Creates an exact copy of this window object.
targetData is written instruction & new data bytes and
then is set to a new window object via a call to its
setData()
method.
targetData - a byte buffer to receive a copy of this wondow data
- a new window object that is an exact copy of this one
getDataLength
public int getDataLength()
Returns the total amount of new data and instruction bytes.
- new data length + instructions length
getInstructionsCount
public int getInstructionsCount()
Returns the amount of instructions of this window object.
- a total number of instructions
getInstructionsLength
public int getInstructionsLength()
Returns the length of instructions in bytes.
- a number of instructions bytes
getNewDataLength
public int getNewDataLength()
Returns the number of new data bytes to copy to the target view.
- a number of new data bytes
getSourceViewLength
public int getSourceViewLength()
Returns the number of bytes to copy from the source view to the target one.
- a number of source bytes to copy
getSourceViewOffset
public long getSourceViewOffset()
Returns the source view offset.
- an offset in the source from where the source bytes
must be copied
getTargetViewLength
public int getTargetViewLength()
Returns the length in bytes of the target view. The length of the target
view is actually the number of bytes that should be totally copied by all the
instructions of this window.
- a length in bytes of the target view
hasCopyFromSourceInstructions
public boolean hasCopyFromSourceInstructions()
Tells whether this window contains any copy-from-source
instructions.
hasInstructions
public boolean hasInstructions()
Tells if this window is not empty, i.e. has got any instructions.
- true if has instructions,
false if has not
instructions
public Iterator instructions()
Returns an iterator to read instructions in series.
Objects returned by an iterator's
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).
instructions
public Iterator instructions(boolean template)
Returns an iterator to read instructions in series.
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.
template - to use a single/multiple instruction objects
loadDiffInstructions
public SVNDiffInstruction[] loadDiffInstructions(SVNDiffInstruction[] target)
Returns an array of instructions of this window.
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.
target - an instructions receiver
- an array containing all instructions
setData
public void setData(ByteBuffer buffer)
Sets a byte buffer containing instruction and new data bytes
of this window.
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.
buffer - an input data buffer
toString
public String toString()
Gives a string representation of this object.
- a string representation of this object
writeNewData
public 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.
target - a buffer to copy tooffset - an offset relative to the position of the first
new data byte of this window objectlength - a number of new data bytes to copy
writeTo
public void writeTo(OutputStream os,
boolean writeHeader)
throws IOException Writes this window object to the provided stream.
If
writeHeader is
true
then writes
SVN_HEADER bytes also.
os - an output stream to write towriteHeader - controls whether the header should be written
or not
writeTo
public void writeTo(OutputStream os,
boolean writeHeader,
boolean compress)
throws IOException Formats and writes this window bytes to the specified output stream.
os - an output stream to write the window towriteHeader - if true a window
header will be also writtencompress - 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)
Copyright © 2004-2006 TMate Software Ltd. All Rights Reserved.