jhplot.io
Class PFile

java.lang.Object
  extended by jhplot.io.PFile

public class PFile
extends Object

Write or read objects in sequential order using Google's Prototype Buffer scheme. Each record inside files is compressed on-fly. The file size are smaller than when using HFile class. All graphical attributes are lost (use HFile class for this). You can unzip the file to see its structure. Normally, files should extension "pbu". Files can be viewed using PFileBrowser. Unlike the usual XML, the file size is small. At this moment, the following objects are supported: a string,P0I, P0D, P1D, PND, PNI, F1D,F2D, FND,PRN, H1D, H2D. A protocol Buffers file is provided which can be used for C++ input. This I/O is mainly for "named" objects (which implement the method setTitle() or setName(). Use CBook package to create such files in C++.

Use this approach for storing P0D, P0I, P1D, H1D, H2D, F1D, F2D objects.


Constructor Summary
PFile(String file)
          Open file for reading objects from a serialized file in sequential order.
PFile(String file, String option)
          Open file for reading objects from a serialized file in sequential order.
PFile(String file, String option, boolean mapNames)
          Open a file to write/read objects to/from a file in sequential order.
 
Method Summary
 boolean close()
          Close the file
 String entriesToString()
          Get a string representing file content.
 ArrayList<jhplot.io.PFile.FileEntry> getEntries()
          Return file entries (ID,name,size).
 int getNEntries()
          Get number of objects stored in the file.
 int getVersion()
          Get version of the input file.
 String listEntries()
          List objects stored in the file.
 boolean mapNames()
          Generate an association between record number and object name.
 Object read()
          Read next object
 Object read(int index)
          Get object from a file using its index.
 Object read(String name)
          Get object from a file using its name.
 int size()
          Get number of objects stored in the file.
 boolean write(Object ob)
          Add an object to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PFile

public PFile(String file,
             String option,
             boolean mapNames)
Open a file to write/read objects to/from a file in sequential order. If "w" option is set, the old file will be removed. Use close() to flash the buffer and close the file. You can set buffer size for I/O . Make it larger for a heavy I/O. It is best to use buffer sizes that are multiples of 1024 bytes. That works best with most built-in buffering in hard disks

Parameters:
file - File name
option - Option to create the file. If "w" - write a file (or read) file, if "r" only read created file.
mapnames - set to true (slower) to make association between object name and its position in the record. In this case, one can read objects as read(name). If file is large and you run over records sequentially using ID, call with "false" for fast load.

PFile

public PFile(String file)
Open file for reading objects from a serialized file in sequential order. This constructor maps names automatically.

Parameters:
file - File name

PFile

public PFile(String file,
             String option)
Open file for reading objects from a serialized file in sequential order. This constructor maps names automatically in the read mode.

Parameters:
option - set "r" to read and "w" to write.
file - File name
Method Detail

mapNames

public boolean mapNames()
Generate an association between record number and object name. Call this method only if the constructor was called without map option.

Returns:
false if something is wrong

getVersion

public int getVersion()
Get version of the input file. The version is an integer written as an additional entry in the file "version". Check this by unzipping the file.

Returns:
version of the created file.

write

public boolean write(Object ob)
Add an object to a file. Can be P1D, P0D,H1D,PND, etc. i.e. any jHplot array

Parameters:
ob - Object
Returns:
true if success

size

public int size()
Get number of objects stored in the file.

Returns:
number of stored objects

getNEntries

public int getNEntries()
Get number of objects stored in the file. Same as size()

Returns:
number of stored objects

getEntries

public ArrayList<jhplot.io.PFile.FileEntry> getEntries()
Return file entries (ID,name,size). It does not return the actual object.

Returns:
file entry

entriesToString

public String entriesToString()
Get a string representing file content.

Returns:
File content.

read

public Object read(String name)
Get object from a file using its name. You should run mapNames() first to create association between names and entries.

Parameters:
name - Name of the object
Returns:
Object extracted object (or null)

read

public Object read()
Read next object

Returns:
next object.

listEntries

public String listEntries()
List objects stored in the file. It list the entry ID, name, entry size and compression size (if available).

Returns:
string with the information about the file

read

public Object read(int index)
Get object from a file using its index.

Parameters:
index - of the object
Returns:
Object extracted object (or null)

close

public boolean close()
Close the file

Returns:


jHepWork 3.1 ©