prefuse.data.io
Class FixedWidthTextTableSchema

java.lang.Object
  extended by prefuse.data.io.FixedWidthTextTableSchema

public class FixedWidthTextTableSchema
extends java.lang.Object

Helper class that stores character length counts for each column in a fixed width text table. This class is needed for reading and writing fixed width data tables. A schema definition can either be created manually using the addColumn(String, int) method or loaded from a tab-delimited text file using the load(String) method.

Author:
jeffrey heer

Constructor Summary
FixedWidthTextTableSchema()
          Creates a new, initially empty FixedWidthTextTableSchema.
 
Method Summary
 void addColumn(java.lang.String name, int length)
          Adds a column to this schema description.
 int getColumnCount()
          Returns the number of columns in this schema.
 int getColumnEnd(int idx)
          Sets the ending character number for the given column index.
 int getColumnLength(int idx)
          Gets the character length of the given column
 java.lang.String getColumnName(int idx)
          Gets the name of the requested column
 int getColumnStart(int idx)
          Gets the starting character number for the given column index
static FixedWidthTextTableSchema load(java.lang.String loc)
          Loads a schema description from the given location.
 void write(java.io.OutputStream os)
          Writes this schema description to the given output stream.
 void write(java.lang.String filename)
          Writes this schema description to a file with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedWidthTextTableSchema

public FixedWidthTextTableSchema()
Creates a new, initially empty FixedWidthTextTableSchema.

Method Detail

addColumn

public void addColumn(java.lang.String name,
                      int length)
Adds a column to this schema description.

Parameters:
name - the name of this column
length - the length, in text characters, of this column in a data file

getColumnCount

public int getColumnCount()
Returns the number of columns in this schema.

Returns:
the numner of columns

getColumnName

public java.lang.String getColumnName(int idx)
Gets the name of the requested column

Parameters:
idx - the index of the column
Returns:
the name of the column

getColumnLength

public int getColumnLength(int idx)
Gets the character length of the given column

Parameters:
idx - the index of the column
Returns:
the character length of the column in the fixed-width format

getColumnStart

public int getColumnStart(int idx)
Gets the starting character number for the given column index

Parameters:
idx - the index of the column
Returns:
the text character position at which this column starts on a line

getColumnEnd

public int getColumnEnd(int idx)
Sets the ending character number for the given column index. This value is one greater than the last character position for the column.

Parameters:
idx - the index of the column
Returns:
one greater than the last text character position at which this column ends on a line

write

public void write(java.lang.String filename)
           throws DataIOException
Writes this schema description to a file with the given name.

Parameters:
filename - the name of the file
Throws:
DataIOException - if an IO exception occurs

write

public void write(java.io.OutputStream os)
           throws DataIOException
Writes this schema description to the given output stream.

Parameters:
os - the output stream
Throws:
DataIOException - if an IO exception occurs

load

public static FixedWidthTextTableSchema load(java.lang.String loc)
                                      throws DataIOException
Loads a schema description from the given location.

Parameters:
loc - a location string representing a filename, URL, or resource locator
Returns:
the loaded schema description
Throws:
DataIOException - if an IO exception occurs


Copyright © 2007 Regents of the University of California