|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.tmatesoft.svn.core.io.diff.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.
SVNDiffInstruction
Field Summary | |
---|---|
static SVNDiffWindow |
EMPTY
An empty window (in particular, its instructions length = 0). |
static byte[] |
SVN_HEADER
Bytes of the delta header of an uncompressed diff window. |
static byte[] |
SVN1_HEADER
Bytes of the delta header of a compressed diff window. |
Constructor Summary | |
---|---|
SVNDiffWindow(long sourceViewOffset,
int sourceViewLength,
int targetViewLength,
int instructionsLength,
int newDataLength)
Constructs an SVNDiffWindow object. |
Method Summary | |
---|---|
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(java.nio.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. |
java.util.Iterator |
instructions()
Returns an iterator to read instructions in series. |
java.util.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(java.nio.ByteBuffer buffer)
Sets a byte buffer containing instruction and new data bytes of this window. |
java.lang.String |
toString()
Gives a string representation of this object. |
void |
writeNewData(java.nio.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(java.io.OutputStream os,
boolean writeHeader)
Writes this window object to the provided stream. |
void |
writeTo(java.io.OutputStream os,
boolean writeHeader,
boolean compress)
Formats and writes this window bytes to the specified output stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final byte[] SVN_HEADER
public static final byte[] SVN1_HEADER
public static final SVNDiffWindow EMPTY
Constructor Detail |
---|
public SVNDiffWindow(long sourceViewOffset, int sourceViewLength, int targetViewLength, int instructionsLength, int newDataLength)
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 dataSVNDiffInstruction
Method Detail |
---|
public int getInstructionsLength()
public long getSourceViewOffset()
public int getSourceViewLength()
public int getTargetViewLength()
public int getNewDataLength()
public java.util.Iterator instructions()
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(boolean)
,
SVNDiffInstruction
public java.util.Iterator instructions(boolean template)
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
instructions()
,
SVNDiffInstruction
public void apply(SVNDiffWindowApplyBaton applyBaton) throws SVNException
applyBaton
.
If this window has got any SVNDiffInstruction.COPY_FROM_SOURCE
instructions, then:
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).
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.
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
SVNException
apply(byte[], byte[])
public int apply(byte[] sourceBuffer, byte[] targetBuffer)
If this window has got any SVNDiffInstruction.COPY_FROM_SOURCE
instructions, then
appropriate bytes described by such an instruction are copied from the sourceBuffer
to the targetBuffer
.
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 targetBuffer
itself.
sourceBuffer
- a buffer containing a source viewtargetBuffer
- a buffer to get a target view
apply(SVNDiffWindowApplyBaton)
public void setData(java.nio.ByteBuffer buffer)
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 bufferpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean hasInstructions()
public void writeTo(java.io.OutputStream os, boolean writeHeader) throws java.io.IOException
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
java.io.IOException
- if an I/O error occurspublic void writeTo(java.io.OutputStream os, boolean writeHeader, boolean compress) throws java.io.IOException
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)
java.io.IOException
public int getDataLength()
public boolean hasCopyFromSourceInstructions()
SVNDiffInstruction.COPY_FROM_SOURCE
instructionpublic SVNDiffWindow clone(java.nio.ByteBuffer targetData)
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
public SVNDiffInstruction[] loadDiffInstructions(SVNDiffInstruction[] target)
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
public int getInstructionsCount()
public void writeNewData(java.nio.ByteBuffer target, int offset, int length)
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |