@Override public int read(long fileOffset, byte[] b, int offSet, int length) throws IOException { return delegate.read(fileOffset, b, offSet, length); }
@Override public int read(long fileOffset, byte[] b, int offSet, int length) throws IOException { return delegate.read(fileOffset, b, offSet, length); }
public void readFully(long fileOffset, byte[] b, int offSet, int length) throws IOException { if (length == 0) { return; } int n = 0; do { int count = this.read(fileOffset + n, b, offSet + n, length - n); if (count <= 0 && length > 0) { throw new IOException("not enough bytes available"); //$NON-NLS-1$ } n += count; } while (n < length); }
public void readFully(long fileOffset, byte[] b, int offSet, int length) throws IOException { if (length == 0) { return; } int n = 0; do { int count = this.read(fileOffset + n, b, offSet + n, length - n); if (count <= 0 && length > 0) { throw new IOException("not enough bytes available"); //$NON-NLS-1$ } n += count; } while (n < length); }
public void readFully(long fileOffset, byte[] b, int offSet, int length) throws IOException { if (length == 0) { return; } int n = 0; do { int count = this.read(fileOffset + n, b, offSet + n, length - n); if (count <= 0 && length > 0) { throw new IOException("not enough bytes available"); //$NON-NLS-1$ } n += count; } while (n < length); }
@Override protected ByteBuffer nextBuffer() throws IOException { int len = bb.capacity(); if (this.streamLength != -1 && len > this.streamLength) { len = (int)this.streamLength; } if (this.streamLength == -1 || this.streamLength > 0) { int bytes = FileStore.this.read(offset, bb.array(), 0, len); if (bytes == -1) { return null; } bb.rewind(); bb.limit(bytes); this.offset += bytes; if (this.streamLength != -1) { this.streamLength -= bytes; } return bb; } return null; } };
@Override protected ByteBuffer nextBuffer() throws IOException { int len = bb.capacity(); if (this.streamLength != -1 && len > this.streamLength) { len = (int)this.streamLength; } if (this.streamLength == -1 || this.streamLength > 0) { int bytes = FileStore.this.read(offset, bb.array(), 0, len); if (bytes == -1) { return null; } bb.rewind(); bb.limit(bytes); this.offset += bytes; if (this.streamLength != -1) { this.streamLength -= bytes; } return bb; } return null; } };
@Override protected ByteBuffer nextBuffer() throws IOException { int len = bb.capacity(); if (this.streamLength != -1 && len > this.streamLength) { len = (int)this.streamLength; } if (this.streamLength == -1 || this.streamLength > 0) { int bytes = FileStore.this.read(offset, bb.array(), 0, len); if (bytes == -1) { return null; } bb.rewind(); bb.limit(bytes); this.offset += bytes; if (this.streamLength != -1) { this.streamLength -= bytes; } return bb; } return null; } };
@Override protected int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException { FileStore store = null; if (!write) { synchronized (this) { if (fileOffset > len) { throw new IOException("Invalid file position " + fileOffset + " length " + length); //$NON-NLS-1$ //$NON-NLS-2$ } store = storageFiles.get((int)(fileOffset/maxFileSize)); } return store.read(fileOffset%maxFileSize, b, offSet, length); } synchronized (this) { ensureLength(fileOffset + length); store = storageFiles.get((int)(fileOffset/maxFileSize)); } long fileBegin = fileOffset%maxFileSize; length = Math.min(length, (int)Math.min(Integer.MAX_VALUE, maxFileSize - fileBegin)); store.write(fileBegin, b, offSet, length); return length; }
@Override protected int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException { FileStore store = null; if (!write) { synchronized (this) { if (fileOffset > len) { throw new IOException("Invalid file position " + fileOffset + " length " + length); //$NON-NLS-1$ //$NON-NLS-2$ } store = storageFiles.get((int)(fileOffset/maxFileSize)); } return store.read(fileOffset%maxFileSize, b, offSet, length); } synchronized (this) { ensureLength(fileOffset + length); store = storageFiles.get((int)(fileOffset/maxFileSize)); } long fileBegin = fileOffset%maxFileSize; length = Math.min(length, (int)Math.min(Integer.MAX_VALUE, maxFileSize - fileBegin)); store.write(fileBegin, b, offSet, length); return length; }
@Override protected int readWrite(long fileOffset, byte[] b, int offSet, int length, boolean write) throws IOException { FileStore store = null; if (!write) { synchronized (this) { if (fileOffset > len) { throw new IOException("Invalid file position " + fileOffset + " length " + length); //$NON-NLS-1$ //$NON-NLS-2$ } store = storageFiles.get((int)(fileOffset/maxFileSize)); } return store.read(fileOffset%maxFileSize, b, offSet, length); } synchronized (this) { ensureLength(fileOffset + length); store = storageFiles.get((int)(fileOffset/maxFileSize)); } long fileBegin = fileOffset%maxFileSize; length = Math.min(length, (int)Math.min(Integer.MAX_VALUE, maxFileSize - fileBegin)); store.write(fileBegin, b, offSet, length); return length; }
@Test public void testInitialRead() throws Exception { FileStorageManager sm = getStorageManager(null, null); String tsID = "0"; //$NON-NLS-1$ FileStore store = sm.createFileStore(tsID); assertEquals(-1, store.read(0, new byte[1], 0, 1)); }