public byte[] readCheckBlock(int segNo, int checkBlockNo) throws IOException { assert (segNo >= 0 && segNo < crossSegments.length); assert (checkBlockNo >= 0 && checkBlockNo < crossCheckBlocks); long offset = offsetCrossSegmentBlocks[segNo] + checkBlockNo * CHKBlock.DATA_LENGTH; byte[] buf = new byte[CHKBlock.DATA_LENGTH]; raf.pread(offset, buf, 0, buf.length); return buf; }
@Override public void pread(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { underlying.pread(fileOffset, buf, bufOffset, length); }
public byte[] readSegmentCheckBlock(int segNo, int checkBlockNo) throws IOException { assert (segNo >= 0 && segNo < segments.length); assert (checkBlockNo >= 0 && checkBlockNo < segments[segNo].checkBlockCount); byte[] buf = new byte[CHKBlock.DATA_LENGTH]; long offset = offsetSegmentCheckBlocks[segNo] + checkBlockNo * CHKBlock.DATA_LENGTH; raf.pread(offset, buf, 0, buf.length); return buf; }
public byte[] readSegmentDataBlock(int segNo, int blockNo) throws IOException { assert (segNo >= 0 && segNo < segments.length); assert (blockNo >= 0 && blockNo < segments[segNo].dataBlockCount); byte[] buf = new byte[CHKBlock.DATA_LENGTH]; if (hasPaddedLastBlock) { if (segNo == segments.length - 1 && blockNo == segments[segNo].dataBlockCount - 1) { // Don't need to lock, locking is just an optimisation. raf.pread(offsetPaddedLastBlock, buf, 0, buf.length); return buf; } } long offset = underlyingOffsetDataSegments[segNo] + blockNo * CHKBlock.DATA_LENGTH; assert(offset < dataLength); assert(offset + buf.length <= dataLength); originalData.pread(offset, buf, 0, buf.length); return buf; }
@Override public void pread(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { synchronized(this) { if(freed) throw new IOException("Already freed"); } underlying.pread(fileOffset, buf, bufOffset, length); }
@Override public void pread(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { if(fileOffset + length > realSize) throw new IOException("Length limit exceeded"); raf.pread(fileOffset, buf, bufOffset, length); }
@Override public void pread(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { if(fileOffset < 0) throw new IllegalArgumentException(); if(fileOffset+length > size) throw new IOException("Tried to read past end of file"); try { lock.readLock().lock(); if(underlying == null || closed) throw new IOException("Already closed"); underlying.pread(fileOffset, buf, bufOffset, length); } finally { lock.readLock().unlock(); } }
byte[] innerReadSegmentKey(int segNo, int blockNo) throws IOException { byte[] buf = new byte[keyLength]; long fileOffset = this.offsetSegmentKeys[segNo] + keyLength * blockNo; if(logDEBUG) Logger.debug(this, "Reading key for block "+blockNo+" for segment "+segNo+" of "+this+" to "+fileOffset); raf.pread(fileOffset, buf, 0, buf.length); return buf; }
void preadChecksummed(long fileOffset, byte[] buf, int offset, int length) throws IOException, ChecksumFailedException { byte[] checksumBuf = new byte[checksumLength]; RAFLock lock = raf.lockOpen(); try { raf.pread(fileOffset, buf, offset, length); raf.pread(fileOffset+length, checksumBuf, 0, checksumLength); } finally { lock.unlock(); } if(!checksumChecker.checkChecksum(buf, offset, length, checksumBuf)) { Arrays.fill(buf, offset, offset+length, (byte)0); throw new ChecksumFailedException(); } }
byte[] preadChecksummedWithLength(long fileOffset) throws IOException, ChecksumFailedException, StorageFormatException { byte[] checksumBuf = new byte[checksumLength]; RAFLock lock = raf.lockOpen(); byte[] lengthBuf = new byte[8]; byte[] buf; int length; try { raf.pread(fileOffset, lengthBuf, 0, lengthBuf.length); long len = new DataInputStream(new ByteArrayInputStream(lengthBuf)).readLong(); if(len + fileOffset > rafLength || len > Integer.MAX_VALUE || len < 0) throw new StorageFormatException("Bogus length "+len); length = (int)len; buf = new byte[length]; raf.pread(fileOffset+lengthBuf.length, buf, 0, length); raf.pread(fileOffset+length+lengthBuf.length, checksumBuf, 0, checksumLength); } finally { lock.unlock(); } if(!checksumChecker.checkChecksum(buf, 0, length, checksumBuf)) { Arrays.fill(buf, 0, length, (byte)0); throw new ChecksumFailedException(); } return buf; }
byte[] preadChecksummedWithLength(long fileOffset) throws IOException, ChecksumFailedException, StorageFormatException { byte[] checksumBuf = new byte[checker.checksumLength()]; RAFLock lock = raf.lockOpen(); byte[] lengthBuf = new byte[8]; byte[] buf; int length; try { raf.pread(fileOffset, lengthBuf, 0, lengthBuf.length); long len = new DataInputStream(new ByteArrayInputStream(lengthBuf)).readLong(); if(len + fileOffset > rafLength || len > Integer.MAX_VALUE || len < 0) throw new StorageFormatException("Bogus length "+len); length = (int)len; buf = new byte[length]; raf.pread(fileOffset+lengthBuf.length, buf, 0, length); raf.pread(fileOffset+length+lengthBuf.length, checksumBuf, 0, checker.checksumLength()); } finally { lock.unlock(); } if(!checker.checkChecksum(buf, 0, length, checksumBuf)) { Arrays.fill(buf, 0, length, (byte)0); throw new ChecksumFailedException(); } return buf; }
@Override public void pread(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { waitForClear(); underlying.pread(fileOffset, buf, bufOffset, length); }
byte[] readBlock(SplitFileFetcherSegmentStorage segment, int slotNumber) throws IOException { long offset = segment.blockOffset(slotNumber); if(logDEBUG) Logger.minor(this, "Reading block "+slotNumber+" for "+segment.segNo+"/"+segments.length+" from "+offset+" RAF length is "+raf.size()); byte[] buf = new byte[CHKBlock.DATA_LENGTH]; raf.pread(offset, buf, 0, buf.length); return buf; }
void preadChecksummed(long fileOffset, byte[] buf, int offset, int length) throws IOException, ChecksumFailedException { byte[] checksumBuf = new byte[checker.checksumLength()]; RAFLock lock = raf.lockOpen(); try { raf.pread(fileOffset, buf, offset, length); raf.pread(fileOffset+length, checksumBuf, 0, checker.checksumLength()); } finally { lock.unlock(); } if(!checker.checkChecksum(buf, offset, length, checksumBuf)) { Arrays.fill(buf, offset, offset+length, (byte)0); throw new ChecksumFailedException(); } }
underlyingBuffer.pread(0, footer, offset, type.headerLen-VERSION_AND_MAGIC_LENGTH);
underlyingBuffer.pread(fileOffset+type.headerLen, cipherText, 0, length);
underlyingBuffer.pread(type.headerLen-VERSION_AND_MAGIC_LENGTH, header, offset, VERSION_AND_MAGIC_LENGTH);
raf.pread(rafLength-8, buf, 0, 8); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); if(dis.readLong() != END_MAGIC) raf.pread(rafLength-12, versionBuf, 0, 4); dis = new DataInputStream(new ByteArrayInputStream(versionBuf)); int version = dis.readInt(); raf.pread(rafLength-14, checksumTypeBuf, 0, 2); dis = new DataInputStream(new ByteArrayInputStream(checksumTypeBuf)); int checksumType = dis.readShort(); raf.pread(rafLength-18, flagsBuf, 0, 4); dis = new DataInputStream(new ByteArrayInputStream(flagsBuf)); int flags = dis.readInt(); raf.pread(rafLength-(22+checksumLength), buf, 0, 4); byte[] checksum = new byte[checksumLength]; raf.pread(rafLength-(18+checksumLength), checksum, 0, checksumLength); System.arraycopy(flagsBuf, 0, buf, 4, 4); System.arraycopy(checksumTypeBuf, 0, buf, 8, 2);
/** Status. Generally depends on the status of the individual segments... * Not persisted: Can be deduced from the state of the segments, except for the last 3 states, * which are only used during completion (we don't keep the storage around once we're * finished). */ enum Status { NOT_STARTED, STARTED, ENCODED_CROSS_SEGMENTS, ENCODED, GENERATING_METADATA, SUCCEEDED, FAILED }