|
JavaSVN Home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.tmatesoft.svn.core.io.diff.SVNDiffWindowBuilder
The SVNDiffWindowBuilder class is used to build diff windows from the raw delta data.
The process of restoring a diff window from raw delta data is represented by the following steps:
HEADER
of this object;
OFFSET
of this object;
INSTRUCTIONS
of this object;
DONE
- the diff window is built and may be got via
calling getDiffWindow()
.
Building a diff window:
When a builder is set to the HEADER
state, at the first calling
to a diff window restoring method - accept() - the builder tries to
read a header. If header bytes are valid, the builder resets itself to
the state OFFSET
.
At the second call to the accept() method
the builder tries to read offsets & lengths, and if succeeds, it resets to
the INSTRUCTIONS
state.
At the next call it reads instructions bytes,
but does not convert them to SVNDiffInstruction objects. So, the
window being produced would not hold instruction objects but only instructions
length, - this is done for memory economy, cause, for example, for large binary files
(tens of Mbs) there could be several hundreds of windows and tens of thousands of
instructions per window what may cause an out of memory exception. When applying a
diff window with the SVNDiffWindow.apply()
method, the method itself will restore diff instructions from the raw instructions data that must
be concatenated with the new data provided to the apply method. But if you need to manually
create diff instructions for the produced window, use the createInstructions()
method.
At last, if instructions have been read successfully,
the builder resets to the DONE
state.
SVNDiffWindow
,
SVNDiffInstruction
Field Summary | |
static int |
DONE
The state of this object that denotes that the current diff window is built, and should be taken back via calling getDiffWindow() . |
static int |
HEADER
The initial state of this object when it's created. |
static int |
INSTRUCTIONS
The state of this object that denotes that diff window instructions are to be read. |
static int |
OFFSET
The state of this object that denotes that diff window offsets are to be read. |
Method Summary | |
int |
accept(byte[] bytes,
int offset)
Builds a diff window from raw delta bytes. |
boolean |
accept(InputStream is,
ISVNEditor consumer,
String path)
Builds a diff window/windows from raw delta bytes. |
static SVNDiffInstruction[] |
createInstructions(byte[] bytes)
Parses, decodes the raw instructions bytes and converts them to diff instruction objects. |
static SVNDiffWindow |
createReplacementDiffWindow(long dataLength)
Creates a diff window intended for replacing the whole contents of a file with new data. |
static SVNDiffWindow[] |
createReplacementDiffWindows(long dataLength,
int maxWindowLength)
Creates a diff window/windows intended for replacing the whole contents of a file with new data. |
SVNDiffWindow |
getDiffWindow()
Returns the built diff window. |
byte[] |
getInstructionsData()
Returns the raw instructions data of the current diff window. |
boolean |
isBuilt()
Says if the current diff window is built. |
static SVNDiffWindowBuilder |
newInstance()
Creates a new diff window builder. |
void |
reset()
Resets this builder to the initial state - HEADER , that
is the very beginning of the raw diff window, its header, is
expected. |
void |
reset(int state)
Resets this builder to a particular state. |
static void |
save(SVNDiffWindow window,
boolean saveHeader,
OutputStream os)
Writes the given diff window to the provided output stream as raw delta bytes. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int HEADER
public static final int OFFSET
public static final int INSTRUCTIONS
public static final int DONE
getDiffWindow()
.
Method Detail |
public static SVNDiffWindowBuilder newInstance()
public void reset()
HEADER
, that
is the very beginning of the raw diff window, its header, is
expected. When calling a diff window restoring method -
accept() - it tries to read a header. If header bytes are
valid, the builder resets itself to the state OFFSET
.
Remember that the inner state of the builder including the produced diff window and its raw instructions data are lost after resetting the builder.
reset(int)
public void reset(int state)
Remember that the inner state of the builder including the produced diff window and its raw instructions data are lost after resetting the builder.
state
- one of the four defined state constantspublic boolean isBuilt()
getDiffWindow()
.
public SVNDiffWindow getDiffWindow()
public byte[] getInstructionsData()
public int accept(byte[] bytes, int offset)
DONE
state) and recursively calls this method to perform
the next step of restoring the window. When this method returns, check if
the diff window is completed by isBuilt()
.
If the raw delta data also includes new data, the return offset will be the offset where this data begins in the provided buffer.
If the bytes
array is not exhausted (i.e. contains more
than just one window), you should obtain the produced window, manually reset
the builder to the OFFSET
state and call this accept() method
again for building the next window.
Actually, diff windows created by the SVNDiffWindowBuilder builders
are not supplied with diff instructions, use createInstructions()
to manually create them.
bytes
- raw delta bytes (header, offsets&lengths, instructions, new data, ...)offset
- an offset in the raw delta bytes array,
that marks the position from where the bytes are
to be read;
accept(InputStream, ISVNEditor, String)
public boolean accept(InputStream is, ISVNEditor consumer, String path) throws SVNException
DONE
state) and returns true.
consumer
is used to collect diff windows and provide output
streams to write raw instructions and new data to for each window.
Actually, diff windows created by the SVNDiffWindowBuilder builders
are not supplied with diff instructions, use createInstructions()
to manually create them. Instructions are written into the same output stream
as the new data (just before the new data):
OutputStream os = consumer.textDeltaChunk(path, window);
is
- a source input stream from where raw delta bytes
are readconsumer
- an editor that collects diff windowspath
- a path of a file for which delta is restored
is
due to
errors
is
(check if
the window isBuilt()
)
SVNException
- if an i/o error occurred while reading from is
public static void save(SVNDiffWindow window, boolean saveHeader, OutputStream os) throws IOException
For the very first diff window saveHeader
must be
true, but if the delta is represented by
more than one diff window, call this method for writing the rest windows
with saveHeader
set to false.
window
- a diff windowsaveHeader
- if true then also writes
delta header (the first three characters of which are
"SVN"), otherwise starts
writing with the window's offsets & lengthsos
- a target output stream where raw delta bytes are to be
written
IOException
- if an i/o error occurredpublic static SVNDiffWindow createReplacementDiffWindow(long dataLength)
The number of instructions depends on the dataLength
: one
instruction per 100K data chunk.
dataLength
- the length of new data
public static SVNDiffWindow[] createReplacementDiffWindows(long dataLength, int maxWindowLength)
The point is that the data length may be too huge, so that one diff window will eat a large amount of memory (on the machine where an svnserve process runs, not JavaSVN) to apply its instructions. It's more safe to devide the contents into a number of smaller windows.
The number of windows produced depends on dataLength
and
maxWindowLength
: one diff window (with a single instruction)
per maxWindowLength
data chunk.
dataLength
- the length of new datamaxWindowLength
- the maximum length of one diff window
public static SVNDiffInstruction[] createInstructions(byte[] bytes)
bytes
- raw instructions bytes
|
JavaSVN Home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |