public void writeSegmentCheckBlock(int segNo, int checkBlockNo, byte[] buf) throws IOException { assert (segNo >= 0 && segNo < segments.length); assert (checkBlockNo >= 0 && checkBlockNo < segments[segNo].checkBlockCount); assert (buf.length == CHKBlock.DATA_LENGTH); long offset = offsetSegmentCheckBlocks[segNo] + checkBlockNo * CHKBlock.DATA_LENGTH; raf.pwrite(offset, buf, 0, buf.length); }
@Override public void pwrite(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { synchronized(this) { if(freed) throw new IOException("Already freed"); } underlying.pwrite(fileOffset, buf, bufOffset, length); }
@Override public void pwrite(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { if(fileOffset + length > realSize) throw new IOException("Length limit exceeded"); raf.pwrite(fileOffset, buf, bufOffset, length); }
/** * Write a cross-check block to disk * * @throws IOException */ void writeCheckBlock(int segNo, int checkBlockNo, byte[] buf) throws IOException { synchronized (this) { if (status == Status.ENCODED || status == Status.ENCODED_CROSS_SEGMENTS) throw new IllegalStateException("Already encoded!?"); } assert (segNo >= 0 && segNo < crossSegments.length); assert (checkBlockNo >= 0 && checkBlockNo < crossCheckBlocks); assert (buf.length == CHKBlock.DATA_LENGTH); long offset = offsetCrossSegmentBlocks[segNo] + checkBlockNo * CHKBlock.DATA_LENGTH; raf.pwrite(offset, buf, 0, buf.length); }
public void close() throws IOException { out.close(); byte[] buf = baos.toByteArray(); if (buf.length != length) throw new IllegalStateException("Wrote wrong number of bytes: " + buf.length + " should be " + length); raf.pwrite(fileOffset, buf, 0, length); }
public void close() throws IOException { out.close(); byte[] buf = baos.toByteArray(); if(buf.length != length) throw new IllegalStateException("Wrote wrong number of bytes: "+buf.length+" should be "+length); raf.pwrite(fileOffset, buf, 0, length); }
@Override public void pwrite(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 write past end of file"); try { lock.readLock().lock(); if(underlying == null || closed) throw new IOException("Already closed"); underlying.pwrite(fileOffset, buf, bufOffset, length); } finally { lock.readLock().unlock(); } }
private void writeOverallStatus(boolean force) throws IOException { byte[] buf; synchronized(this) { if(!persistent) return; if(!force && !overallStatusDirty) return; buf = encodeOverallStatus(); assert(buf.length == overallStatusLength); } raf.pwrite(offsetOverallStatus, buf, 0, buf.length); }
void writeBlock(SplitFileFetcherSegmentStorage segment, int slotNumber, byte[] data) throws IOException { raf.pwrite(segment.blockOffset(slotNumber), data, 0, data.length); }
private synchronized void writeGeneralProgress(boolean force) { if(!dirtyGeneralProgress && !force) return; dirtyGeneralProgress = false; byte[] generalProgress = encodeGeneralProgress(); try { raf.pwrite(offsetGeneralProgress, generalProgress, 0, generalProgress.length); } catch (IOException e) { failOnDiskError(e); } }
void innerWriteSegmentKey(int segNo, int blockNo, byte[] buf) throws IOException { assert (buf.length == SplitFileInserterSegmentStorage.getKeyLength(this)); assert (segNo >= 0 && segNo < segments.length); assert (blockNo >= 0 && blockNo < segments[segNo].totalBlockCount); long fileOffset = this.offsetSegmentKeys[segNo] + keyLength * blockNo; if(logDEBUG) Logger.debug(this, "Writing key for block "+blockNo+" for segment "+segNo+" of "+this+" to "+fileOffset); raf.pwrite(fileOffset, buf, 0, buf.length); }
@Override public void pwrite(long fileOffset, byte[] buf, int bufOffset, int length) throws IOException { waitForClear(); underlying.pwrite(fileOffset, buf, bufOffset, length); }
System.arraycopy(magic, 0, header, offset, magic.length); underlyingBuffer.pwrite(0, header, 0, header.length);
@Override public LockableRandomAccessBuffer makeRAF(byte[] initialContents, int offset, int size, boolean readOnly) throws IOException { boolean reallyEncrypt = false; synchronized(this) { reallyEncrypt = this.reallyEncrypt; } if(reallyEncrypt) { // FIXME do the encryption in memory? Test it ... LockableRandomAccessBuffer ret = makeRAF(size); ret.pwrite(0, initialContents, offset, size); if(readOnly) ret = new ReadOnlyRandomAccessBuffer(ret); return ret; } else { return factory.makeRAF(initialContents, offset, size, readOnly); } }
writeLock.unlock(); underlyingBuffer.pwrite(fileOffset+type.headerLen, cipherText, 0, length);
ret.pwrite(0, initialContents, offset, size); if(readOnly) ret = new ReadOnlyRandomAccessBuffer(ret); return ret;
/** 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 }
for(SplitFileFetcherSegmentStorage segment : segments) segment.writeMetadata(); raf.pwrite(offsetGeneralProgress, generalProgress, 0, generalProgress.length); keyListener.innerWriteMainBloomFilter(offsetMainBloomFilter); keyListener.initialWriteSegmentBloomFilters(offsetSegmentBloomFilters); BucketTools.copyTo(metadataTemp, raf, offsetOriginalMetadata, -1); metadataTemp.free(); raf.pwrite(offsetOriginalDetails, encodedURI, 0, encodedURI.length); raf.pwrite(offsetBasicSettings, encodedBasicSettings, 0, encodedBasicSettings.length); checksumChecker.generateChecksum(bufToChecksum); raf.pwrite(offsetBasicSettings + encodedBasicSettings.length, bufToWrite, 0, bufToWrite.length); raf.pwrite(offsetBasicSettings + encodedBasicSettings.length + bufToWrite.length, checksum, 0, checksum.length); raf.pwrite(offsetBasicSettings + encodedBasicSettings.length + bufToWrite.length + checksum.length, version, 0, version.length); dos.writeLong(END_MAGIC); byte[] buf = baos.toByteArray(); raf.pwrite(totalLength - 8, buf, 0, 8);