jhplot.io
Class HFile
- java.lang.Object
-
- jhplot.io.HFile
-
public class HFile extends java.lang.Object
Write or read objects in sequential order using the Java serialization. The objects inside files are gzipped on-fly. The size of serialized files should be significantly smaller than when using HFile class. Use "close()" to flush buffered output stream. Use BrowserHFile to browser all entries in a GUI frame. Normally, files should have the extension ".jser". Files can be viewed using BrowserHFile.You can also insert objects using the keys and read them back. In this case, avoid writing many objects without the keys since the extraction of keys will be very inefficient. Try not mix write/read with keys or without.
-
-
Constructor Summary
Constructors Constructor and Description HFile(java.lang.String file)
Open file for reading objects from a serialized file in sequential order.HFile(java.lang.String file, java.lang.String option)
Open file for reading objects from a serialized file in sequential order.HFile(java.lang.String file, java.lang.String option, boolean compression)
Open a file to write/read objects to/from a serialized file in sequential order.HFile(java.lang.String file, java.lang.String option, boolean compression, int bufferSize)
Open a file to write/read objects to/from a serialized file in sequential order.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean
close()
Close the filevoid
doc()
Show online documentation.int
getBufferSize()
Get current buffer size for I/O.int
getEntries()
Return processed number of entries.java.util.Map<java.lang.String,java.lang.Object>
getObjectMap()
Return objects stored in the form of a map.java.lang.Object
read()
Get object from a file.java.lang.Object
read(java.lang.String key)
Read an object using a key if exits.void
setFlush(int reset)
Set after how many events data will be flushed.boolean
write(java.lang.Object ob)
Add an object to a fileboolean
write(java.lang.String key, java.lang.Object ob)
Add an object using a key.
-
-
-
Constructor Detail
-
HFile
public HFile(java.lang.String file, java.lang.String option, boolean compression, int bufferSize)
Open a file to write/read objects to/from a serialized file in sequential order. Objects can be gzipped/gunzipped on-fly. 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.You can also insert an object using a string key.
If the file name starts from http or ftp, we assume it is located on the Web and will attempt to read it from URL.
- Parameters:
file
- File name. Can be located on URL if starts from http or ftp.option
- Option to create the file. If "w" - write a file (or read) file, if "r" only read created file.compression
- if true, objects are compressed on-fly using GZIPbufferSize
- set buffer size for I/O. It is best to use buffer sizes that are multiples of 1024 bytes.
-
HFile
public HFile(java.lang.String file, java.lang.String option, boolean compression)
Open a file to write/read objects to/from a serialized file in sequential order. Objects can be gzipped/gunzipped on-fly. If "w" option is set, the old file will be removed. Use close() to flash the buffer and close the file. The default buffer size is 12 k (i.e. 12 * 1024).- Parameters:
file
- File nameoption
- Option to create the file. If "w" - write a file (or read) file, if "r" only read created file.compression
- if true, objects are compressed on-fly using GZIPbuffer
- set buffer size for I/O. It is best to use buffer sizes that are multiples of 1024 bytes.
-
HFile
public HFile(java.lang.String file)
Open file for reading objects from a serialized file in sequential order. By default, entries are compressed.- Parameters:
file
- File name
-
HFile
public HFile(java.lang.String file, java.lang.String option)
Open file for reading objects from a serialized file in sequential order. By default, objects are compressed.- Parameters:
file
- File nameoption
- Option to create the file. If "w" - write a file (or read) file, if "r" only read created file.
-
-
Method Detail
-
getBufferSize
public int getBufferSize()
Get current buffer size for I/O.
-
write
public boolean write(java.lang.String key, java.lang.Object ob)
Add an object using a key.- Parameters:
key
- key to access the object.ob
- object to be inserted.- Returns:
- false if the key exits.
-
write
public boolean write(java.lang.Object ob)
Add an object to a file- Parameters:
ob
- Objectkey
- key for object- Returns:
- true if success
-
setFlush
public void setFlush(int reset)
Set after how many events data will be flushed. The stream will flush all the objects from the identity hash table. The default is 100.- Parameters:
reset
- after how many events data will be reset.
-
getObjectMap
public java.util.Map<java.lang.String,java.lang.Object> getObjectMap()
Return objects stored in the form of a map.- Returns:
-
getEntries
public int getEntries()
Return processed number of entries. Entries with the key not counted.- Returns:
- No of processed events
-
read
public java.lang.Object read()
Get object from a file. Return Null if the end if file is reached.- Returns:
- Object extracted object (or Null)
-
read
public java.lang.Object read(java.lang.String key)
Read an object using a key if exits.- Parameters:
key
-- Returns:
- returned object.
-
close
public boolean close()
Close the file- Returns:
-
doc
public void doc()
Show online documentation.
-
-
DMelt 3.0 © DataMelt by jWork.ORG