mnist.tools
Class MnistDbFile

java.lang.Object
  extended by java.io.RandomAccessFile
      extended by mnist.tools.MnistDbFile
All Implemented Interfaces:
java.io.Closeable, java.io.DataInput, java.io.DataOutput
Direct Known Subclasses:
MnistImageFile, MnistLabelFile

public abstract class MnistDbFile
extends java.io.RandomAccessFile

MNIST database file containing entries that can represent image or label data. Extends the standard random access file with methods for navigating over the entries. The file format is basically idx with specific header information. This includes a magic number for determining the type of stored entries, count of entries.


Constructor Summary
MnistDbFile(java.lang.String name, java.lang.String mode)
          Creates new instance and reads the header information.
 
Method Summary
 int getCount()
           
 long getCurrentIndex()
          The current entry index.
 int getEntryLength()
          Number of bytes for each entry.
 int getHeaderSize()
           
 void next()
          Move to the next entry.
 void prev()
          Move to the previous entry.
 void setCurrentIndex(long curr)
          Set the required current entry index.
 
Methods inherited from class java.io.RandomAccessFile
close, getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MnistDbFile

public MnistDbFile(java.lang.String name,
                   java.lang.String mode)
            throws java.io.IOException,
                   java.io.FileNotFoundException
Creates new instance and reads the header information.

Parameters:
name - the system-dependent filename
mode - the access mode
Throws:
java.io.IOException
java.io.FileNotFoundException
See Also:
RandomAccessFile
Method Detail

getCurrentIndex

public long getCurrentIndex()
                     throws java.io.IOException
The current entry index.

Returns:
long
Throws:
java.io.IOException

setCurrentIndex

public void setCurrentIndex(long curr)
Set the required current entry index.

Parameters:
curr - the entry index

getHeaderSize

public int getHeaderSize()

getEntryLength

public int getEntryLength()
Number of bytes for each entry. Defaults to 1.

Returns:
int

next

public void next()
          throws java.io.IOException
Move to the next entry.

Throws:
java.io.IOException

prev

public void prev()
          throws java.io.IOException
Move to the previous entry.

Throws:
java.io.IOException

getCount

public int getCount()