Package ucar.unidata.io.zarr
Class RandomAccessDirectory
- java.lang.Object
-
- ucar.unidata.io.RandomAccessFile
-
- ucar.unidata.io.zarr.RandomAccessDirectory
-
- All Implemented Interfaces:
Closeable
,DataInput
,DataOutput
,AutoCloseable
,FileCacheable
public class RandomAccessDirectory extends RandomAccessFile implements FileCacheable, Closeable
This class allows a directory structure to be read in memory as a single file. RandomAccessDirectory implemented a tree structure with files as leaves. It is read-only - writes should use the leaf RandomAccessFile write methods
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RandomAccessDirectory.Provider
Hook into service provider interface to RandomAccessFileProvider.
-
Field Summary
Fields Modifier and Type Field Description protected int
bufferSize
protected List<RandomAccessDirectoryItem>
children
-
Fields inherited from class ucar.unidata.io.RandomAccessFile
allFiles, BIG_ENDIAN, bigEndian, buffer, bufferModified, bufferStart, dataEnd, dataSize, debugAccess, debugLeaks, defaultBufferSize, endOfFile, file, fileChannel, filePosition, LITTLE_ENDIAN, location, openFiles, readonly, showOpen, showRead
-
-
Constructor Summary
Constructors Constructor Description RandomAccessDirectory(String location)
RandomAccessDirectory(String location, int bufferSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the file, and release any associated system resources.RandomAccessDirectoryItem
getFileAtPos(int pos)
Return the directory item containing the specified positionList<RandomAccessDirectoryItem>
getFilesInPath(String path)
Find all files in the store that fall under the given pathlong
getLastModified()
Returns the time that the underlying file(s) were last modified.boolean
isDirectory()
Returns true if RandomAccessFile represents a directory structurelong
length()
Get the length of the file.protected int
read_(long pos, byte[] b, int offset, int len)
Read directly from file, without going through the buffer.long
readToByteChannel(WritableByteChannel dest, long offset, long nbytes)
Readnbytes
bytes, at the specified file offset, send to a WritableByteChannel.protected void
setFileToPos(long pos)
sets current RandomAccessFile to that containing pos saves start position on current RAFvoid
write(int b)
Not implemented - use write methods on the leaf RandomAccessFile e.g.void
writeBytes(byte[] b, int off, int len)
Not implemented - use write methods on the leaf RandomAccessFile e.g.-
Methods inherited from class ucar.unidata.io.RandomAccessFile
acquire, acquire, eject, enableDefaultGlobalFileCache, flush, getAllFiles, getBufferSize, getDebugLeaks, getDebugNbytes, getDebugNseeks, getFilePointer, getGlobalFileCache, getLocation, getMaxOpenFileCount, getOpenFileCount, getOpenFiles, getRandomAccessFile, isAtEndOfFile, order, order, reacquire, read, read, read, readBoolean, readBuffer, readByte, readBytes, readBytes, readChar, readDouble, readDouble, readFloat, readFloat, readFully, readFully, readInt, readInt, readIntUnbuffered, readLine, readLine, readLong, readLong, readShort, readShort, readString, readString, readStringMax, readStringMax, readUnsignedByte, readUnsignedShort, readUTF, release, searchForward, seek, setBufferSize, setDebugAccess, setDebugLeaks, setExtendMode, setFileCache, setGlobalFileCache, setMinLength, shutdown, skipBytes, skipBytes, toString, unread, write, write, writeBoolean, writeBoolean, writeByte, writeBytes, writeBytes, writeChar, writeChar, writeChar, writeChar, writeChar, writeChar, writeChars, writeChars, writeChars, writeDouble, writeDouble, writeDouble, writeDouble, writeDouble, writeDouble, writeFloat, writeFloat, writeFloat, writeFloat, writeFloat, writeFloat, writeInt, writeInt, writeInt, writeInt, writeInt, writeInt, writeLong, writeLong, writeLong, writeLong, writeLong, writeLong, writeShort, writeShort, writeShort, writeShort, writeShort, writeShort, writeUTF
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ucar.nc2.util.cache.FileCacheable
getLocation, reacquire, release, setFileCache
-
-
-
-
Field Detail
-
children
protected List<RandomAccessDirectoryItem> children
-
bufferSize
protected int bufferSize
-
-
Constructor Detail
-
RandomAccessDirectory
public RandomAccessDirectory(String location) throws IOException
- Throws:
IOException
-
RandomAccessDirectory
public RandomAccessDirectory(String location, int bufferSize) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getFileAtPos
public RandomAccessDirectoryItem getFileAtPos(int pos)
Return the directory item containing the specified position- Parameters:
pos
-- Returns:
- Directory item containing bytes at `pos`
-
getFilesInPath
public List<RandomAccessDirectoryItem> getFilesInPath(String path) throws IOException
Find all files in the store that fall under the given path- Parameters:
path
-- Returns:
- list of files in path
- Throws:
IOException
-
setFileToPos
protected void setFileToPos(long pos) throws IOException
sets current RandomAccessFile to that containing pos saves start position on current RAF- Parameters:
pos
-- Throws:
IOException
-
close
public void close() throws IOException
Description copied from class:RandomAccessFile
Close the file, and release any associated system resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceFileCacheable
- Overrides:
close
in classRandomAccessFile
- Throws:
IOException
- if an I/O error occurrs.
-
getLastModified
public long getLastModified()
Description copied from interface:FileCacheable
Returns the time that the underlying file(s) were last modified. If they've changed since they were stored in the cache, they will be closed and reopened withFileFactory
.- Specified by:
getLastModified
in interfaceFileCacheable
- Overrides:
getLastModified
in classRandomAccessFile
- Returns:
- a
long
value representing the time the file(s) were last modified or0L
if the last-modified time couldn't be determined for any reason.
-
isDirectory
public boolean isDirectory()
Description copied from class:RandomAccessFile
Returns true if RandomAccessFile represents a directory structure- Overrides:
isDirectory
in classRandomAccessFile
-
length
public long length()
Description copied from class:RandomAccessFile
Get the length of the file. The data in the buffer (which may not have been written the disk yet) is taken into account.- Overrides:
length
in classRandomAccessFile
- Returns:
- the length of the file in bytes.
-
readToByteChannel
public long readToByteChannel(WritableByteChannel dest, long offset, long nbytes) throws IOException
Description copied from class:RandomAccessFile
Readnbytes
bytes, at the specified file offset, send to a WritableByteChannel. This will block until all bytes are read. This uses the underlying file channel directly, bypassing all user buffers.- Overrides:
readToByteChannel
in classRandomAccessFile
- Parameters:
dest
- write to this WritableByteChannel.offset
- the offset in the file where copying will start.nbytes
- the number of bytes to read.- Returns:
- the actual number of bytes read and transfered
- Throws:
IOException
- if an I/O error occurs.
-
read_
protected int read_(long pos, byte[] b, int offset, int len) throws IOException
Description copied from class:RandomAccessFile
Read directly from file, without going through the buffer. All reading goes through here or readToByteChannel;- Overrides:
read_
in classRandomAccessFile
- Parameters:
pos
- start here in the fileb
- put data into this bufferoffset
- buffer offsetlen
- this number of bytes- Returns:
- actual number of bytes read, -1 if underlying random access file was closed
- Throws:
IOException
- on io error
-
write
public void write(int b)
Not implemented - use write methods on the leaf RandomAccessFile e.g. getCurrentFile().write()- Specified by:
write
in interfaceDataOutput
- Overrides:
write
in classRandomAccessFile
- Parameters:
b
- write this byte
-
writeBytes
public void writeBytes(byte[] b, int off, int len)
Not implemented - use write methods on the leaf RandomAccessFile e.g. getCurrentFile().write()- Overrides:
writeBytes
in classRandomAccessFile
- Parameters:
b
- the array containing the data.off
- the offset in the array to the data.len
- the length of the data.
-
-