Package gov.nasa.pds.label.object
Class DataObject
- java.lang.Object
-
- gov.nasa.pds.label.object.DataObject
-
- Direct Known Subclasses:
ArrayObject
,GenericObject
,TableObject
public abstract class DataObject extends java.lang.Object
Defines a base type for objects within a label.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.channels.SeekableByteChannel
channel
protected DataObjectLocation
dataObjectLocation
protected File
fileObject
protected java.lang.String
localIdentifier
protected java.lang.String
name
protected long
offset
protected java.net.URL
parentDir
-
Constructor Summary
Constructors Modifier Constructor Description protected
DataObject(java.io.File parentDir, long offset, long size)
protected
DataObject(java.io.File parentDir, File fileObject, long offset, long size)
protected
DataObject(java.net.URL parentDir, File fileObject, long offset, long size, DataObjectLocation location)
protected
DataObject(java.net.URL parentDir, File fileObject, long offset, long size, DataObjectLocation location, java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeChannel()
Closes the underlying channel to the data.java.nio.channels.SeekableByteChannel
getChannel()
Gets aSeekableByteChannel
for accessing the data object.java.net.URL
getDataFile()
Gets a url that refers to the data file for this object.DataObjectLocation
getDataObjectLocation()
java.io.InputStream
getInputStream()
Gets an input stream to the data object.java.lang.String
getLocalIdentifier()
java.lang.String
getName()
long
getOffset()
Gets the offset within the data file where the object data begins.long
getSize()
Gets the size of the data object within the data file.void
setDataObjectLocation(DataObjectLocation dataObjectLocation)
void
setLocalIdentifier(java.lang.String localIdentifier)
void
setName(java.lang.String name)
protected void
setSize(long newSize)
-
-
-
Field Detail
-
parentDir
protected java.net.URL parentDir
-
fileObject
protected File fileObject
-
offset
protected long offset
-
name
protected java.lang.String name
-
localIdentifier
protected java.lang.String localIdentifier
-
channel
protected java.nio.channels.SeekableByteChannel channel
-
dataObjectLocation
protected DataObjectLocation dataObjectLocation
-
-
Constructor Detail
-
DataObject
protected DataObject(java.io.File parentDir, long offset, long size) throws java.io.IOException
- Throws:
java.io.IOException
-
DataObject
protected DataObject(java.io.File parentDir, File fileObject, long offset, long size) throws java.io.IOException
- Throws:
java.io.IOException
-
DataObject
protected DataObject(java.net.URL parentDir, File fileObject, long offset, long size, DataObjectLocation location) throws java.io.IOException, java.net.URISyntaxException
- Throws:
java.io.IOException
java.net.URISyntaxException
-
DataObject
protected DataObject(java.net.URL parentDir, File fileObject, long offset, long size, DataObjectLocation location, java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getDataFile
public java.net.URL getDataFile() throws java.net.MalformedURLException
Gets a url that refers to the data file for this object.- Returns:
- a
URL
for the file containing the data object - Throws:
java.net.MalformedURLException
-
getOffset
public long getOffset()
Gets the offset within the data file where the object data begins.- Returns:
- the offset to the data
-
getSize
public long getSize()
Gets the size of the data object within the data file.- Returns:
- the size of the data object, in bytes
-
setSize
protected void setSize(long newSize)
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Gets an input stream to the data object. This input stream will read from the first byte in the data object to the last byte within that object. Other bytes outside of the range for the data object will not be accessed.- Returns:
- an input stream to the data object
- Throws:
java.io.FileNotFoundException
- if the data file cannot be foundjava.io.IOException
- if there is an error reading the data file
-
getChannel
public java.nio.channels.SeekableByteChannel getChannel() throws java.io.IOException
Gets aSeekableByteChannel
for accessing the data object. The channel is read-only, and represents only the portion of the data file containing the data object. You must remember to call the closeChannel() method once reading of the data is finished.- Returns:
- a
SeekableByteChannel
for reading bytes from the data object - Throws:
java.io.IOException
- if there is an error reading the data file
-
closeChannel
public void closeChannel()
Closes the underlying channel to the data.
-
getName
public java.lang.String getName()
-
setName
public void setName(java.lang.String name)
-
getDataObjectLocation
public DataObjectLocation getDataObjectLocation()
-
setDataObjectLocation
public void setDataObjectLocation(DataObjectLocation dataObjectLocation)
-
getLocalIdentifier
public java.lang.String getLocalIdentifier()
-
setLocalIdentifier
public void setLocalIdentifier(java.lang.String localIdentifier)
-
-