@Override public final void setDataInput(final DataInput dataInput) { this.dataInput = dataInput; this.dataInputSize = dataInput.getSize(); } //
@Override public void writeExternal(final ObjectOutput out) throws IOException { super.writeExternal(out); out.writeInt(layersCacheCountLimit); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); layersCacheCountLimit = in.readInt(); }
dataIoTask.setCurrRangeIdx(currRangeIdx); } else { throw new DataSizeException(item.size(), countBytesDone + chunkSize); chunkCountDone += remainingSize; } catch(final DataCorruptionException e) { throw new DataCorruptionException( getRangeOffset(dataIoTask.getCurrRangeIdx()) + e.getOffset(), e.expected, e.actual );
} else { if(chunkSize > item.size() - countBytesDone) { throw new DataSizeException(item.size(), countBytesDone + chunkSize); dataIoTask.setCountBytesDone(e.getOffset()); dataIoTask.setStatus(IoTask.Status.RESP_FAIL_CORRUPT); if(e instanceof DataSizeException) { Loggers.MSG.debug( "{}: invalid size, expected: {}, actual: {} ", dataItem.getName(), dataItem.size(), e.getOffset() ); } catch(final IOException ignored) { Loggers.MSG.debug( "{}: content mismatch @ offset {}, expected: {}, actual: {} ", dataItem.getName(), ee.getOffset(), String.format("\"0x%X\"", (int) (ee.expected & 0xFF)), String.format("\"0x%X\"", (int) (ee.actual & 0xFF))
throw new DataSizeException(contentSize, countBytesDone); } else { countBytesDone += n; throw new DataSizeException(contentSize, countBytesDone); countBytesDone += e.getOffset(); ioTask.setCountBytesDone(countBytesDone); Loggers.MSG.debug(
@Override public final int write(final ByteBuffer src) throws DataCorruptionException, DataSizeException { if(src == null) { return 0; } int m; final MappedByteBuffer ringBuff = (MappedByteBuffer) dataInput .getLayer(layerNum) .asReadOnlyBuffer(); ringBuff.position((int) ((offset + position) % dataInputSize)); final int n = Math.min(src.remaining(), ringBuff.remaining()); if(n > 0) { byte bs, bi; for(m = 0; m < n; m ++) { bs = ringBuff.get(); bi = src.get(); if(bs != bi) { throw new DataCorruptionException(m, bs, bi); } } position += n; } else { return n; } return m; }
wi >>= 8; if(bs != bi) { throw new DataCorruptionException(wordPos + i, bs, bi); bi = inBuff.get(); if(bs != bi) { throw new DataCorruptionException(m, bs, bi);
) throws DataCorruptionException, IOException { if(chunkSize > dataIoTask.getMarkedRangesSize() - countBytesDone) { throw new DataSizeException( dataIoTask.getMarkedRangesSize(), countBytesDone + chunkSize );
instance = new ExternalDataInput( rbc, (int) layerSizeBytes, layerCacheLimit ); instance = new SeedDataInput( Long.parseLong(seed, 0x10), (int) layerSizeBytes, layerCacheLimit );
(xorShift(getInitialSeed()) << layerIndex) ^ layerIndex ); generateData(layer, layerSeed); layersCache.put(layerIndex - 1, layer);
@Override public final void verify(final ByteBuffer inBuff) throws DataCorruptionException { final ByteBuffer ringBuff = dataInput.getLayer(layerNum).asReadOnlyBuffer(); ringBuff.position((int) ((offset + position) % dataInputSize)); verify(inBuff, ringBuff); }
public SeedDataInput(final long seed, final int size, final int cacheLimit) { super((MappedByteBuffer) ByteBuffer.allocateDirect(size), cacheLimit); generateData(inputBuff, seed); }
@Override public final String toString() { return Long.toHexString(getInitialSeed()) + ',' + Integer.toHexString(inputBuff.capacity()); } }
public void close() throws IOException { super.close(); final Int2ObjectOpenHashMap<MappedByteBuffer> layersCache = thrLocLayersCache.get(); if(layersCache != null) { for(final MappedByteBuffer layer : layersCache.values()) { DirectMemUtil.free(layer); } layersCache.clear(); thrLocLayersCache.set(null); } }
@Override protected void doClose() throws IOException, IllegalStateException { try( final Instance logCtx = CloseableThreadContext .put(KEY_TEST_STEP_ID, stepId) .put(KEY_CLASS_NAME, StorageDriverBase.class.getSimpleName()) ) { ioTasksDispatchCoroutine.close(); itemDataInput.close(); childTasksQueue.clear(); inTasksQueue.clear(); final int ioResultsQueueSize = ioResultsQueue.size(); if(ioResultsQueueSize > 0) { Loggers.ERR.warn( "{}: I/O results queue contains {} unhandled elements", toString(), ioResultsQueueSize ); } ioResultsQueue.clear(); authTokens.clear(); pathToCredMap.clear(); pathMap.clear(); Loggers.MSG.debug("{}: closed", toString()); } }
final int n = srcChannel.read(inBuff); if(n < 0) { throw new DataSizeException(rangesSizeSum, countBytesDone); } else { inBuff.flip(); countBytesDone += n; } catch(final DataCorruptionException e) { throw new DataCorruptionException( currPos + e.getOffset() - countBytesDone, e.expected, e.actual );
@Override public final int read(final ByteBuffer dst) { final int n; final MappedByteBuffer ringBuff = (MappedByteBuffer) dataInput .getLayer(layerNum) .asReadOnlyBuffer(); ringBuff.position((int) ((offset + position) % dataInputSize)); // bytes count to transfer n = Math.min(dst.remaining(), ringBuff.remaining()); ringBuff.limit(ringBuff.position() + n); // do the transfer dst.put(ringBuff); position += n; return n; } //
@Override public final long writeToFileChannel(final FileChannel chanDst, final long maxCount) throws IOException { final MappedByteBuffer ringBuff = (MappedByteBuffer) dataInput .getLayer(layerNum) .asReadOnlyBuffer(); int n = (int) ((offset + position) % dataInputSize); ringBuff.position(n); n = (int) Math.min(maxCount, ringBuff.remaining()); ringBuff.limit(ringBuff.position() + n); n = chanDst.write(ringBuff); position += n; return n; }
@Override public final long writeToSocketChannel(final WritableByteChannel chanDst, final long maxCount) throws IOException { final MappedByteBuffer ringBuff = (MappedByteBuffer) dataInput .getLayer(layerNum) .asReadOnlyBuffer(); long doneCount = 0; int n, m; // spin while not done either destination channel consumes all the data while(doneCount < maxCount) { ringBuff.position((int) ((offset + position) % dataInputSize)); n = (int) Math.min(maxCount - doneCount, ringBuff.remaining()); ringBuff.limit(ringBuff.position() + n); m = chanDst.write(ringBuff); doneCount += m; position += m; if(m < n) { break; } } return doneCount; }