@Override protected int getBlockStoreBlockSize() { return getBigBlockSize(); }
public static void dump(POIFSFileSystem fs, int startBlock, String name, File parent) throws IOException { File file = new File(parent, name); try (FileOutputStream out = new FileOutputStream(file)) { POIFSStream stream = new POIFSStream(fs, startBlock); byte[] b = IOUtils.safelyAllocate(fs.getBigBlockSize(), MAX_RECORD_LENGTH); for (ByteBuffer bb : stream) { int len = bb.remaining(); bb.get(b); out.write(b, 0, len); } } } }
/** * Load the block at the given offset. */ protected ByteBuffer getBlockAt(final int offset) { // Which big block is this? int byteOffset = offset * POIFSConstants.SMALL_BLOCK_SIZE; int bigBlockNumber = byteOffset / _filesystem.getBigBlockSize(); int bigBlockOffset = byteOffset % _filesystem.getBigBlockSize(); // Now locate the data block for it Iterator<ByteBuffer> it = _mini_stream.getBlockIterator(); for(int i=0; i<bigBlockNumber; i++) { it.next(); } ByteBuffer dataBlock = it.next(); if(dataBlock == null) { throw new IndexOutOfBoundsException("Big block " + bigBlockNumber + " outside stream"); } // Position ourselves, and take a slice dataBlock.position( dataBlock.position() + bigBlockOffset ); ByteBuffer miniBuffer = dataBlock.slice(); miniBuffer.limit(POIFSConstants.SMALL_BLOCK_SIZE); return miniBuffer; }
/** * Load the block at the given offset, * extending the file if needed */ @Override protected ByteBuffer createBlockIfNeeded(final int offset) throws IOException { try { return getBlockAt(offset); } catch(IndexOutOfBoundsException e) { // The header block doesn't count, so add one long startAt = (offset+1L) * bigBlockSize.getBigBlockSize(); // Allocate and write ByteBuffer buffer = ByteBuffer.allocate(getBigBlockSize()); _data.write(buffer, startAt); // Retrieve the properly backed block return getBlockAt(offset); } }
@Override protected int getBlockStoreBlockSize() { return getBigBlockSize(); }
public static void dump(POIFSFileSystem fs, int startBlock, String name, File parent) throws IOException { File file = new File(parent, name); try (FileOutputStream out = new FileOutputStream(file)) { POIFSStream stream = new POIFSStream(fs, startBlock); byte[] b = IOUtils.safelyAllocate(fs.getBigBlockSize(), MAX_RECORD_LENGTH); for (ByteBuffer bb : stream) { int len = bb.remaining(); bb.get(b); out.write(b, 0, len); } } } }
/** * Load the block at the given offset. */ protected ByteBuffer getBlockAt(final int offset) { // Which big block is this? int byteOffset = offset * POIFSConstants.SMALL_BLOCK_SIZE; int bigBlockNumber = byteOffset / _filesystem.getBigBlockSize(); int bigBlockOffset = byteOffset % _filesystem.getBigBlockSize(); // Now locate the data block for it Iterator<ByteBuffer> it = _mini_stream.getBlockIterator(); for(int i=0; i<bigBlockNumber; i++) { it.next(); } ByteBuffer dataBlock = it.next(); if(dataBlock == null) { throw new IndexOutOfBoundsException("Big block " + bigBlockNumber + " outside stream"); } // Position ourselves, and take a slice dataBlock.position( dataBlock.position() + bigBlockOffset ); ByteBuffer miniBuffer = dataBlock.slice(); miniBuffer.limit(POIFSConstants.SMALL_BLOCK_SIZE); return miniBuffer; }
/** * Load the block at the given offset, * extending the file if needed */ @Override protected ByteBuffer createBlockIfNeeded(final int offset) throws IOException { try { return getBlockAt(offset); } catch(IndexOutOfBoundsException e) { // The header block doesn't count, so add one long startAt = (offset+1L) * bigBlockSize.getBigBlockSize(); // Allocate and write ByteBuffer buffer = ByteBuffer.allocate(getBigBlockSize()); _data.write(buffer, startAt); // Retrieve the properly backed block return getBlockAt(offset); } }