RegisterSign In

API Documentation: Class StringData

Package: com.mckoi.data

An object that wraps a DataFile to provide an mutable string object of any size. This object is useful for implementing character string based stored data items (textual documents, logs, etc).

This class provides efficient methods for character iteration, substring by location, and string removal and insertion by location. Each character of the string is stored as a 16 bit char primitive.

Constructors Summary

StringData(DataFile data)

Methods Summary

long length()
void writeString(long pos, String str)
void append(String str)
void insert(long pos, String str)
void remove(long pos, long size)
String substring(long pos, int size)
String toString()
java.text.CharacterIterator getCharacterIterator()
Reader getReader()
Writer getWriter(long pos)
Writer getWriter()

Constructor Details

StringData(DataFile data)

Constructs the string object mapped to the given DataFile object.

Method Details

long length()

Returns the number of characters in the string. This operation is a function of the size of the mapped data file, therefore a fast computation.

void writeString(long pos, String str)

Writes a string to the given position in the string object overwriting any string characters that may already be there, and expanding the size of the data file to accommodate any characters that may be written past the end of the current size of the string. 'pos' = 0 is the first character, 1 is the second character, etc.

void append(String str)

Appends a string to the end of the data, expanding the size of the file to accommodate the new data.

void insert(long pos, String str)

Inserts a string at the given position in the text area shifting all text after the position forward by the size of the string being inserted and expanding the length of the string object by the size of the inserted string. 'pos' = 0 is the first character, 1 is the second character, etc.

void remove(long pos, long size)

Removes a section of the text area and shifts text past the area into the space removed and shrinking the length of the string object. 'pos' = 0 is the first character, 1 is the second character, etc.

String substring(long pos, int size)

Returns a substring of the string data object where 'pos' is the position of the first character of the substring and 'size' is the size of the substring in characters.

String toString()

Returns the entire string data object as a string.

java.text.CharacterIterator getCharacterIterator()

Returns a CharacterIterator object over the complete string. The returned object is undefined if the data changes while this iterator is in use.

Reader getReader()

Returns a java.io.Reader object that can be used to read characters sequentially in the string. The behavior of the returned object is undefined if the data changes while this object is in use.

Writer getWriter(long pos)

Returns a java.io.Writer object that can be used to write characters at the given position. Any existing characters in the data object from the given position will be overwritten. The behavior of the returned object is undefined if the data changes while this object is in use.

Writer getWriter()

Returns a java.io.Writer object that can be used to write characters to the string object from the start position onwards. Any existing information in the data object will be overwritten. This is the same as 'getWriter(0)'.

The text on this page is licensed under the Creative Commons Attribution 3.0 License. Java is a registered trademark of Oracle and/or its affiliates.
Mckoi is Copyright © 2000 - 2018 Diehl and Associates, Inc. All rights reserved.