@Test @UseDataProvider("provideInvalidStreams") public void invalidRead(final InputStream in, final OutputStream out) throws IOException { this.thrown.expect(NullPointerException.class); ObjectFile.read(in, out, true); }
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);  }