public InputStream serialize() throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bytes); out.writeByte(fileType.ordinal()); if (isFile()) { out.writeInt(blocks.length); for (int i = 0; i < blocks.length; i++) { out.writeLong(blocks[i].getId()); out.writeLong(blocks[i].getLength()); } } out.close(); return new ByteArrayInputStream(bytes.toByteArray()); }
private synchronized void nextBlockOutputStream() throws IOException { long blockId = r.nextLong(); while (store.blockExists(blockId)) { blockId = r.nextLong(); } nextBlock = new Block(blockId, bytesWrittenToBlock); blocks.add(nextBlock); bytesWrittenToBlock = 0; }
private static long findBlocksize(INode inode) { final Block[] ret = inode.getBlocks(); return ret == null ? 0L : ret[0].getLength(); } }
public void testSerializeFileWithSingleBlock() throws IOException { Block[] blocks = { new Block(849282477840258181L, 128L) }; INode inode = new INode(FileType.FILE, blocks); assertEquals("Length", 1L + 4 + 16, inode.getSerializedLength()); InputStream in = inode.serialize(); INode deserialized = INode.deserialize(in); assertEquals("FileType", inode.getFileType(), deserialized.getFileType()); Block[] deserializedBlocks = deserialized.getBlocks(); assertEquals("Length", 1, deserializedBlocks.length); assertEquals("Id", blocks[0].getId(), deserializedBlocks[0].getId()); assertEquals("Length", blocks[0].getLength(), deserializedBlocks[0] .getLength()); }
public void deleteBlock(Block block) throws IOException { blocks.remove(block.getId()); }
public S3InputStream(Configuration conf, FileSystemStore store, INode inode, FileSystem.Statistics stats) { this.store = store; this.stats = stats; this.blocks = inode.getBlocks(); for (Block block : blocks) { this.fileLength += block.getLength(); } }
private String blockToKey(Block block) { return blockToKey(block.getId()); }
public InputStream serialize() throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bytes); out.writeByte(fileType.ordinal()); if (isFile()) { out.writeInt(blocks.length); for (int i = 0; i < blocks.length; i++) { out.writeLong(blocks[i].getId()); out.writeLong(blocks[i].getLength()); } } out.close(); return new ByteArrayInputStream(bytes.toByteArray()); }
private static long findBlocksize(INode inode) { final Block[] ret = inode.getBlocks(); return ret == null ? 0L : ret[0].getLength(); } }
private String blockToKey(Block block) { return blockToKey(block.getId()); }
private synchronized void nextBlockOutputStream() throws IOException { long blockId = r.nextLong(); while (store.blockExists(blockId)) { blockId = r.nextLong(); } nextBlock = new Block(blockId, bytesWrittenToBlock); blocks.add(nextBlock); bytesWrittenToBlock = 0; }
public InputStream serialize() throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bytes); try { out.writeByte(fileType.ordinal()); if (isFile()) { out.writeInt(blocks.length); for (int i = 0; i < blocks.length; i++) { out.writeLong(blocks[i].getId()); out.writeLong(blocks[i].getLength()); } } out.close(); out = null; } finally { IOUtils.closeStream(out); } return new ByteArrayInputStream(bytes.toByteArray()); }
public S3InputStream(Configuration conf, FileSystemStore store, INode inode, FileSystem.Statistics stats) { this.store = store; this.stats = stats; this.blocks = inode.getBlocks(); for (Block block : blocks) { this.fileLength += block.getLength(); } }
private String blockToKey(Block block) { return blockToKey(block.getId()); }
private synchronized void nextBlockOutputStream() throws IOException { long blockId = r.nextLong(); while (store.blockExists(blockId)) { blockId = r.nextLong(); } nextBlock = new Block(blockId, bytesWrittenToBlock); blocks.add(nextBlock); bytesWrittenToBlock = 0; }
public S3InputStream(Configuration conf, FileSystemStore store, INode inode, FileSystem.Statistics stats) { this.store = store; this.stats = stats; this.blocks = inode.getBlocks(); for (Block block : blocks) { this.fileLength += block.getLength(); } }
public void storeBlock(Block block, File file) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[8192]; int numRead; BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); while ((numRead = in.read(buf)) >= 0) { out.write(buf, 0, numRead); } } finally { if (in != null) { in.close(); } } blocks.put(block.getId(), out.toByteArray()); }
public static INode deserialize(InputStream in) throws IOException { if (in == null) { return null; } DataInputStream dataIn = new DataInputStream(in); FileType fileType = INode.FILE_TYPES[dataIn.readByte()]; switch (fileType) { case DIRECTORY: in.close(); return INode.DIRECTORY_INODE; case FILE: int numBlocks = dataIn.readInt(); Block[] blocks = new Block[numBlocks]; for (int i = 0; i < numBlocks; i++) { long id = dataIn.readLong(); long length = dataIn.readLong(); blocks[i] = new Block(id, length); } in.close(); return new INode(fileType, blocks); default: throw new IllegalArgumentException("Cannot deserialize inode."); } }
private static long findBlocksize(INode inode) { final Block[] ret = inode.getBlocks(); return ret == null ? 0L : ret[0].getLength(); } }