Elements of the sequence are the lines of the file, as delimited by the UNIX newline character ('\n'). The file content is treated as 8 bit binary text, with no assumptions or requirements on character encoding.
Note that the first line of the file is element 0, as defined by the Sequence interface API. Traditionally in a text editor a patch file the first line is line number 1. Callers may need to subtract 1 prior to invoking methods if they are converting from "line number" to "element index".
| Modifier and Type | Field and Description |
|---|---|
| private static final AtomicInteger | BUFFER_SIZE
Number of bytes to check for heuristics in |
| protected final byte[] | content
The file content for this sequence. |
| public static final RawText | EMPTY_TEXT
A RawText of length 0 |
| private static final int | FIRST_FEW_BYTES
Default and minimum for |
| protected final IntList |
| Access | Constructor and Description |
|---|---|
| public | RawText(byte[]
the content array. The object retains a reference to this
array, so it should be immutable. input)Create a new sequence from an existing content byte array. |
| public | RawText(byte[]
the content array. The object retains a reference to this
array, so it should be immutable. input, IntList an array with 1-based offsets for the start of each line.
The first and last entries should be lineMap)Integer#MIN_VALUE
and an offset one past the end of the last line, respectively.Create a new sequence from the existing content byte array and the line map indicating line boundaries. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected String | Returns: the region[start, end) decoded as a String.first byte of the content to decode. start, int one past the last byte of the content to decode. end)Decode a region of the text into a String. |
| public static int | Returns: the buffer size, by defaultFIRST_FEW_BYTES bytesObtains the buffer size to use for analyzing whether certain content is text or binary, or what line endings are used if it's text. |
| private int | |
| public String | |
| public byte[] | |
| public ByteBuffer | Returns: the text for the line, without a trailing LF, as aByteBuffer that is backed by a slice of the
raw content, with the buffer's position
on the start of the line and the limit at the end.index of the line to extract. Note this is 0-based, so line
number 1 is actually index 0. i)Get the raw text for a single line. |
| private int | |
| public String | Returns: the text for the line, without a trailing LF.index of the line to extract. Note this is 0-based, so line
number 1 is actually index 0. i)Get the text for a single line. |
| public String | Returns: the text for lines[begin, end).index of the first line to extract. Note this is 0-based, so
line number 1 is actually index 0. begin, int index of one past the last line to extract. end, boolean if true the trailing LF ('\n') of the last returned line is
dropped, if present. dropLF)Get the text for a region of lines. |
| public static boolean | Returns: true if raw is likely to be a binary file, false otherwiseinput stream containing the raw file content. raw)Determine heuristically whether the bytes contained in a stream represents binary (as opposed to text) content. |
| public static boolean | Returns: true if raw is likely to be a binary file, false otherwisethe raw file content. raw)Determine heuristically whether a byte array represents binary (as opposed to text) content. |
| public static boolean | Returns: true if raw is likely to be a binary file, false otherwisethe raw file content. raw, int number of bytes in length)raw to evaluate. This should be
raw.length unless raw was over-allocated by
the caller.Determine heuristically whether a byte array represents binary (as opposed to text) content. |
| public static boolean | Returns: true if raw is likely to be a binary file, false otherwisethe raw file content. raw, int number of bytes in length, boolean raw to evaluate. This should be
raw.length unless raw was over-allocated by
the caller.whether complete)raw contains the whole dataDetermine heuristically whether a byte array represents binary (as opposed to text) content. |
| public static boolean | Returns: true if either byte is NUL, or if prev is CR and curr is
not LF, false otherwisethe last byte, read after curr, byte prevthe previous byte, read before prev)lastDetermines from the last two bytes read from a source if it looks like binary content. |
| public static boolean | Returns: true if raw is likely to be CR-LF delimited text,
false otherwisethe raw file content. raw)Determine heuristically whether a byte array represents text content using CR-LF as line separator. |
| public static boolean | Returns: true if raw is likely to be CR-LF delimited text,
false otherwiseinput stream containing the raw file content. raw)Determine heuristically whether the bytes contained in a stream represent text content using CR-LF as line separator. |
| public static boolean | Returns: true if raw is likely to be CR-LF delimited text,
false otherwisethe raw file content. raw, int number of bytes in length)raw to evaluate.Determine heuristically whether a byte array represents text content using CR-LF as line separator. |
| public static boolean | Returns: true if raw is likely to be CR-LF delimited text,
false otherwisethe raw file content. raw, int number of bytes in length, boolean raw to evaluate.whether complete)raw contains the whole dataDetermine heuristically whether a byte array represents text content using CR-LF as line separator. |
| public boolean | Returns: true if the last line has an LF; false otherwise.Determine if the file ends with a LF ('\n'). |
| public static RawText | Returns: the RawText representing the blob.the ObjectLoader for the blob ldr, int if the blob is larger than this size, it is always assumed to
be binary. threshold)Read a blob object into RawText, or throw BinaryBlobException if the blob is binary. |
| public static int | Returns: the size actually setSize to set bufferSize)Sets the buffer size to use for analyzing whether certain content is text or binary, or what line endings are used if it's text. |
| public int | Returns: total number of items in the sequence.Implements abstract org. Get size |
| public void | writeLine(OutputStream
stream to copy the line data onto. out, int index of the line to extract. Note this is 0-based, so line
number 1 is actually index 0. i)Write a specific line to the output stream, without its trailing LF. |
| BUFFER_SIZE | back to summary |
|---|---|
| private static final AtomicInteger BUFFER_SIZE Number of bytes to check for heuristics in | |
| content | back to summary |
|---|---|
| protected final byte[] content The file content for this sequence. | |
| EMPTY_TEXT | back to summary |
|---|---|
| public static final RawText EMPTY_TEXT A RawText of length 0 | |
| FIRST_FEW_BYTES | back to summary |
|---|---|
| private static final int FIRST_FEW_BYTES Default and minimum for | |
| lines | back to summary |
|---|---|
| protected final IntList lines Map of line number to starting position within | |
| RawText | back to summary |
|---|---|
| public RawText(byte[] input) Create a new sequence from an existing content byte array. The entire array (indexes 0 through length-1) is used as the content.
| |
| RawText | back to summary |
|---|---|
| public RawText(byte[] input, IntList lineMap) Create a new sequence from the existing content byte array and the line map indicating line boundaries.
| |
| RawText | back to summary |
|---|---|
| public RawText(File file) throws IOException Create a new sequence from a file. The entire file contents are used.
| |
| decode | back to summary |
|---|---|
| protected String decode(int start, int end) Decode a region of the text into a String. The default implementation of this method tries to guess the character set by considering UTF-8, the platform default, and falling back on ISO-8859-1 if neither of those can correctly decode the region given.
| |
| getBufferSize | back to summary |
|---|---|
| public static int getBufferSize() Obtains the buffer size to use for analyzing whether certain content is text or binary, or what line endings are used if it's text.
| |
| getEnd | back to summary |
|---|---|
| private int getEnd(int i) | |
| getLineDelimiter | back to summary |
|---|---|
| public String getLineDelimiter() Get the line delimiter for the first line.
| |
| getRawContent | back to summary |
|---|---|
| public byte[] getRawContent() Get the raw content
| |
| getRawString | back to summary |
|---|---|
| public ByteBuffer getRawString(int i) Get the raw text for a single line.
| |
| getStart | back to summary |
|---|---|
| private int getStart(int i) | |
| getString | back to summary |
|---|---|
| public String getString(int i) Get the text for a single line.
| |
| getString | back to summary |
|---|---|
| public String getString(int begin, int end, boolean dropLF) Get the text for a region of lines.
| |
| isBinary | back to summary |
|---|---|
| public static boolean isBinary(InputStream raw) throws IOException Determine heuristically whether the bytes contained in a stream represents binary (as opposed to text) content. Note Do not further use this stream after having called this method! The stream may not be fully read and will be left at an unknown position after consuming an unknown number of bytes. The caller is responsible for closing the stream.
| |
| isBinary | back to summary |
|---|---|
| public static boolean isBinary(byte[] raw) Determine heuristically whether a byte array represents binary (as opposed to text) content.
| |
| isBinary | back to summary |
|---|---|
| public static boolean isBinary(byte[] raw, int length) Determine heuristically whether a byte array represents binary (as opposed to text) content.
| |
| isBinary | back to summary |
|---|---|
| public static boolean isBinary(byte[] raw, int length, boolean complete) Determine heuristically whether a byte array represents binary (as opposed to text) content.
| |
| isBinary | back to summary |
|---|---|
| public static boolean isBinary(byte curr, byte prev) Determines from the last two bytes read from a source if it looks like binary content.
| |
| isCrLfText | back to summary |
|---|---|
| public static boolean isCrLfText(byte[] raw) Determine heuristically whether a byte array represents text content using CR-LF as line separator.
| |
| isCrLfText | back to summary |
|---|---|
| public static boolean isCrLfText(InputStream raw) throws IOException Determine heuristically whether the bytes contained in a stream represent text content using CR-LF as line separator. Note Do not further use this stream after having called this method! The stream may not be fully read and will be left at an unknown position after consuming an unknown number of bytes. The caller is responsible for closing the stream.
| |
| isCrLfText | back to summary |
|---|---|
| public static boolean isCrLfText(byte[] raw, int length) Determine heuristically whether a byte array represents text content using CR-LF as line separator.
| |
| isCrLfText | back to summary |
|---|---|
| public static boolean isCrLfText(byte[] raw, int length, boolean complete) Determine heuristically whether a byte array represents text content using CR-LF as line separator.
| |
| isMissingNewlineAtEnd | back to summary |
|---|---|
| public boolean isMissingNewlineAtEnd() Determine if the file ends with a LF ('\n').
| |
| load | back to summary |
|---|---|
| public static RawText load(ObjectLoader ldr, int threshold) throws IOException, BinaryBlobException Read a blob object into RawText, or throw BinaryBlobException if the blob is binary.
| |
| setBufferSize | back to summary |
|---|---|
| public static int setBufferSize(int bufferSize) Sets the buffer size to use for analyzing whether certain content is text
or binary, or what line endings are used if it's text. If the given
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract org. Doc from org. Get size
| |
| writeLine | back to summary |
|---|---|
| public void writeLine(OutputStream out, int i) throws IOException Write a specific line to the output stream, without its trailing LF. The specified line is copied as-is, with no character encoding translation performed. If the specified line ends with an LF ('\n'), the LF is not copied. It is up to the caller to write the LF, if desired, between output lines.
| |