com.nothome.delta.text
Class GDiffTextWriter

java.lang.Object
  extended by com.nothome.delta.text.GDiffTextWriter
All Implemented Interfaces:
DiffTextWriter, Closeable

public class GDiffTextWriter
extends Object
implements DiffTextWriter

A text-file format analog for GDIFF, which is only supported for binary streams. The output follows the following extended BNF format:

 gdiff-text ::= header , { copy | data }
 header ::= 'gdt' , { version } , '\n'
 copy   ::= 'y' offset ',' length '\n'
 data   ::= 'i' length '\n' text-chunk '\n'
 length ::= hex-digit , { hex-digit }
 offset ::= hex-digit , { hex-digit }
 hex-digit  ::= '0'-'9' | 'a'-'f'
 text-chunk ::= (* arbitrary text string *)
 version ::= '1'-'9'
 
Note that 'y' is used for copy and 'i' for data since they aren't to be confused with the hex characters 'c' and 'd'.

Note that the length of text-string is capped at CHUNK_SIZE characters for this implementation.

The initial version is 1 and is optionally indicated. Newer versions may support additional commands and hints.

See also: http://www.w3.org/TR/NOTE-gdiff-19970901.html.


Field Summary
static int CHUNK_SIZE
          Max length of a "text-chunk".
static char COMMA
          Comma delimiter.
static char COPY
          Copy command character.
static char DATA
          Data command character.
static char LF
          Line feed character.
 
Constructor Summary
GDiffTextWriter(Writer w)
          Constructs a new GDiffTextWriter.
 
Method Summary
 void addCopy(int offset, int length)
          Add a copy command.
 void addData(char c)
          Add a character to output.
 void close()
          Frees internal resources; closes output stream.
 void flush()
          Writes current state to output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LF

public static final char LF
Line feed character.

See Also:
Constant Field Values

COPY

public static final char COPY
Copy command character.

See Also:
Constant Field Values

DATA

public static final char DATA
Data command character.

See Also:
Constant Field Values

COMMA

public static final char COMMA
Comma delimiter.

See Also:
Constant Field Values

CHUNK_SIZE

public static final int CHUNK_SIZE
Max length of a "text-chunk". Although this could be arbitrarily large, this caps the buffer size, facilitating reading.

See Also:
Constant Field Values
Constructor Detail

GDiffTextWriter

public GDiffTextWriter(Writer w)
                throws IOException
Constructs a new GDiffTextWriter.

Parameters:
w -
Throws:
IOException
Method Detail

addCopy

public void addCopy(int offset,
                    int length)
             throws IOException
Description copied from interface: DiffTextWriter
Add a copy command.

Specified by:
addCopy in interface DiffTextWriter
Parameters:
offset - start of sequence
length - length of sequence
Throws:
IOException

addData

public void addData(char c)
             throws IOException
Description copied from interface: DiffTextWriter
Add a character to output.

Specified by:
addData in interface DiffTextWriter
Throws:
IOException

flush

public void flush()
           throws IOException
Description copied from interface: DiffTextWriter
Writes current state to output stream.

Specified by:
flush in interface DiffTextWriter
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: DiffTextWriter
Frees internal resources; closes output stream.

Specified by:
close in interface DiffTextWriter
Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2003-2008. All Rights Reserved.