@Test public void read() throws IOException { final String objectString = UUID.randomUUID().toString().replace("-", "") + "0000"; final LegacyObjectMetadata object = LegacyObjectMetadata.fromMetadata(objectString, 1024, 0, (byte)0, -1); ByteBuffer inputBuffer = ByteBuffer.allocate(ObjectFileVersion.VERSION_HEADER_LENGTH + LegacyObjectMetadata.OBJECT_SIZE); inputBuffer.put(ObjectFileVersion.fromMetadata((byte)2, (byte)0).getBytes()); inputBuffer.put(object.toBytes()); final InputStream in = new ByteArrayInputStream(inputBuffer.array()); final ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectFile.read(in, out, true); ByteBuffer outBuffer = ByteBuffer.wrap(out.toByteArray()); outBuffer.position(ObjectFileVersion.VERSION_HEADER_LENGTH); byte[] objectBuffer = new byte[LegacyObjectMetadata.OBJECT_SIZE]; outBuffer.get(objectBuffer, 0, LegacyObjectMetadata.OBJECT_SIZE); assertThat(new String(out.toByteArray()), is(String.format("%s:%s.%s\n%s,%s,%s,%s,%s%n", "VERSION", LegacyObjectMetadata.MAJOR_VERSION, LegacyObjectMetadata.MINOR_VERSION, object.getName(), object.getSize(), object.getContainerSuffix(), object.getNumberOfLegalHolds(), object.getRetention()))); }
public static void read(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8)); final ByteBuffer objectBuffer = ByteBuffer.allocate(LegacyObjectMetadata.OBJECT_SIZE); ObjectFileVersion version = ObjectFileUtil.readObjectFileVersion(in); final byte[] readBytes = ObjectFileUtil.allocateObjectBuffer(version.getMajorVersion(), version.getMinorVersion(), in); int skipLength = ObjectFileUtil.getVersionHeaderLength(version.getMajorVersion(), version.getMinorVersion()); in.skip(skipLength); if (writeVersionHeader) { writer.write("VERSION:" + LegacyObjectMetadata.MAJOR_VERSION + "." + LegacyObjectMetadata.MINOR_VERSION); writer.newLine(); } while (readFully(in, readBytes)) { final ObjectMetadata objectName = ObjectFileUtil.getObjectFromInputBuffer(version.getMajorVersion(), version.getMinorVersion(), readBytes, objectBuffer.array()); writer.write(String.format("%s,%s,%s,%s,%s", objectName.getName(), objectName.getSize(), objectName.getContainerSuffix(), objectName.getNumberOfLegalHolds(), objectName.getRetention())); writer.newLine(); } } finally { if (writer != null) { writer.flush(); } } }
ObjectFile { public static void read(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8)); final ByteBuffer objectBuffer = ByteBuffer.allocate(LegacyObjectMetadata.OBJECT_SIZE); ObjectFileVersion version = ObjectFileUtil.readObjectFileVersion(in); final byte[] readBytes = ObjectFileUtil.allocateObjectBuffer(version.getMajorVersion(), version.getMinorVersion(), in); int skipLength = ObjectFileUtil.getVersionHeaderLength(version.getMajorVersion(), version.getMinorVersion()); in.skip(skipLength); if (writeVersionHeader) { writer.write("VERSION:" + LegacyObjectMetadata.MAJOR_VERSION + "." + LegacyObjectMetadata.MINOR_VERSION); writer.newLine(); } while (readFully(in, readBytes)) { final ObjectMetadata objectName = ObjectFileUtil.getObjectFromInputBuffer(version.getMajorVersion(), version.getMinorVersion(), readBytes, objectBuffer.array()); writer.write(String.format("%s,%s,%s,%s,%s", objectName.getName(), objectName.getSize(), objectName.getContainerSuffix(), objectName.getNumberOfLegalHolds(), objectName.getRetention())); writer.newLine(); } } finally { if (writer != null) { writer.flush(); } } } }
ObjectFile { public static void read(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8)); final ByteBuffer objectBuffer = ByteBuffer.allocate(LegacyObjectMetadata.OBJECT_SIZE); ObjectFileVersion version = ObjectFileUtil.readObjectFileVersion(in); final byte[] readBytes = ObjectFileUtil.allocateObjectBuffer(version.getMajorVersion(), version.getMinorVersion(), in); int skipLength = ObjectFileUtil.getVersionHeaderLength(version.getMajorVersion(), version.getMinorVersion()); in.skip(skipLength); if (writeVersionHeader) { writer.write("VERSION:" + LegacyObjectMetadata.MAJOR_VERSION + "." + LegacyObjectMetadata.MINOR_VERSION); writer.newLine(); } while (readFully(in, readBytes)) { final ObjectMetadata objectName = ObjectFileUtil.getObjectFromInputBuffer(version.getMajorVersion(), version.getMinorVersion(), readBytes, objectBuffer.array()); writer.write(String.format("%s,%s,%s,%s,%s", objectName.getName(), objectName.getSize(), objectName.getContainerSuffix(), objectName.getNumberOfLegalHolds(), objectName.getRetention())); writer.newLine(); } } finally { if (writer != null) { writer.flush(); } } } private  ObjectFile(); }
ObjectFile { public static void read(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8)); final ByteBuffer objectBuffer = ByteBuffer.allocate(LegacyObjectMetadata.OBJECT_SIZE); ObjectFileVersion version = ObjectFileUtil.readObjectFileVersion(in); final byte[] readBytes = ObjectFileUtil.allocateObjectBuffer(version.getMajorVersion(), version.getMinorVersion(), in); int skipLength = ObjectFileUtil.getVersionHeaderLength(version.getMajorVersion(), version.getMinorVersion()); in.skip(skipLength); if (writeVersionHeader) { writer.write("VERSION:" + LegacyObjectMetadata.MAJOR_VERSION + "." + LegacyObjectMetadata.MINOR_VERSION); writer.newLine(); } while (readFully(in, readBytes)) { final ObjectMetadata objectName = ObjectFileUtil.getObjectFromInputBuffer(version.getMajorVersion(), version.getMinorVersion(), readBytes, objectBuffer.array()); writer.write(String.format("%s,%s,%s,%s,%s", objectName.getName(), objectName.getSize(), objectName.getContainerSuffix(), objectName.getNumberOfLegalHolds(), objectName.getRetention())); writer.newLine(); } } finally { if (writer != null) { writer.flush(); } } } private  ObjectFile(); static void main(final String[] args); static InputStream getInputStream(final File input); static OutputStream getOutputStream(final boolean split, final int splitSize,
      final String output); static OutputStream getOutputStream(final String output); static void write(final InputStream in, final OutputStream out, boolean writeVersionHeader); static void read(final InputStream in, final OutputStream out, boolean writeVersionHeader); static void filter(final InputStream in, final OutputStream out, final long minFilesize,
      final long maxFilesize, final int minContainerSuffix, final int maxContainerSuffix,
      final Set<Integer> containerSuffixes, final int minLegalholds, final int maxLegalHolds,
      final long minRetention, final long maxRetention, boolean writeVersionHeader); static void split(final InputStream in, final OutputStream out); static void upgrade(final InputStream in, final OutputStream out); static boolean readFully(final InputStream in, final byte[] b); static void compactObjectFiles(final HashMap<File, Integer> objectFiles, final int maxcount); static void combineFiles(File f1, File f2); static void randomShuffleObjects(final InputStream in, final OutputStream out); static void shuffle(String prefix, String directory, int maxObjects); }
ObjectFile { public static void read(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(out, Charsets.UTF_8)); final ByteBuffer objectBuffer = ByteBuffer.allocate(LegacyObjectMetadata.OBJECT_SIZE); ObjectFileVersion version = ObjectFileUtil.readObjectFileVersion(in); final byte[] readBytes = ObjectFileUtil.allocateObjectBuffer(version.getMajorVersion(), version.getMinorVersion(), in); int skipLength = ObjectFileUtil.getVersionHeaderLength(version.getMajorVersion(), version.getMinorVersion()); in.skip(skipLength); if (writeVersionHeader) { writer.write("VERSION:" + LegacyObjectMetadata.MAJOR_VERSION + "." + LegacyObjectMetadata.MINOR_VERSION); writer.newLine(); } while (readFully(in, readBytes)) { final ObjectMetadata objectName = ObjectFileUtil.getObjectFromInputBuffer(version.getMajorVersion(), version.getMinorVersion(), readBytes, objectBuffer.array()); writer.write(String.format("%s,%s,%s,%s,%s", objectName.getName(), objectName.getSize(), objectName.getContainerSuffix(), objectName.getNumberOfLegalHolds(), objectName.getRetention())); writer.newLine(); } } finally { if (writer != null) { writer.flush(); } } } private  ObjectFile(); static void main(final String[] args); static InputStream getInputStream(final File input); static OutputStream getOutputStream(final boolean split, final int splitSize,
      final String output); static OutputStream getOutputStream(final String output); static void write(final InputStream in, final OutputStream out, boolean writeVersionHeader); static void read(final InputStream in, final OutputStream out, boolean writeVersionHeader); static void filter(final InputStream in, final OutputStream out, final long minFilesize,
      final long maxFilesize, final int minContainerSuffix, final int maxContainerSuffix,
      final Set<Integer> containerSuffixes, final int minLegalholds, final int maxLegalHolds,
      final long minRetention, final long maxRetention, boolean writeVersionHeader); static void split(final InputStream in, final OutputStream out); static void upgrade(final InputStream in, final OutputStream out); static boolean readFully(final InputStream in, final byte[] b); static void compactObjectFiles(final HashMap<File, Integer> objectFiles, final int maxcount); static void combineFiles(File f1, File f2); static void randomShuffleObjects(final InputStream in, final OutputStream out); static void shuffle(String prefix, String directory, int maxObjects);  }