@Test public void writeV1() throws IOException { final String objectName = UUID.randomUUID().toString().replace("-", "") + "0000"; final String objectMetadata = objectName + ",0,0"; final ByteBuffer inputByteBuffer = ByteBuffer.allocate(objectMetadata.getBytes().length); inputByteBuffer.put(objectMetadata.getBytes()); final InputStream in = new ByteArrayInputStream(inputByteBuffer.array()); final ByteArrayOutputStream out = new ByteArrayOutputStream(ObjectFileVersion.VERSION_HEADER_LENGTH + LegacyObjectMetadata.OBJECT_SIZE); ObjectFile.write(in, out, true); ByteBuffer outputBuffer = ByteBuffer.wrap(out.toByteArray()); outputBuffer.position(ObjectFileVersion.VERSION_HEADER_LENGTH); byte[] filteredBytes = new byte[LegacyObjectMetadata.OBJECT_SIZE]; outputBuffer.get(filteredBytes, 0, LegacyObjectMetadata.OBJECT_SIZE); final ObjectMetadata object = LegacyObjectMetadata.fromBytes(filteredBytes); final LegacyObjectMetadata expectedObject = LegacyObjectMetadata.fromMetadata(objectName, 0, 0, (byte)0, -1); assertThat(String.format("%s,%s,%s,%s,%s", expectedObject.getName(), expectedObject.getSize(), expectedObject.getContainerSuffix(), expectedObject.getNumberOfLegalHolds(), expectedObject.getRetention()), is(String.format("%s,%s,%s,%s,%s", object.getName(), object.getSize(), object.getContainerSuffix(), object.getNumberOfLegalHolds(), object.getRetention()))); }
public static void write(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8)); String line; if (writeVersionHeader) { ObjectFileUtil.writeObjectFileVersion(out); } line = reader.readLine(); ObjectFileVersion version = null; if (line != null) { version = ObjectFileVersion.fromCharString(line); if (version.getMajorVersion() == 1 && version.getMinorVersion() == 0) { LegacyObjectMetadata objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } ObjectMetadata objectName = null; while ((line = reader.readLine()) != null) { objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } }
ObjectFile { public static void write(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8)); String line; if (writeVersionHeader) { ObjectFileUtil.writeObjectFileVersion(out); } line = reader.readLine(); ObjectFileVersion version = null; if (line != null) { version = ObjectFileVersion.fromCharString(line); if (version.getMajorVersion() == 1 && version.getMinorVersion() == 0) { LegacyObjectMetadata objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } ObjectMetadata objectName = null; while ((line = reader.readLine()) != null) { objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } }
ObjectFile { public static void write(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8)); String line; if (writeVersionHeader) { ObjectFileUtil.writeObjectFileVersion(out); } line = reader.readLine(); ObjectFileVersion version = null; if (line != null) { version = ObjectFileVersion.fromCharString(line); if (version.getMajorVersion() == 1 && version.getMinorVersion() == 0) { LegacyObjectMetadata objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } ObjectMetadata objectName = null; while ((line = reader.readLine()) != null) { objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } private  ObjectFile(); }
ObjectFile { public static void write(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8)); String line; if (writeVersionHeader) { ObjectFileUtil.writeObjectFileVersion(out); } line = reader.readLine(); ObjectFileVersion version = null; if (line != null) { version = ObjectFileVersion.fromCharString(line); if (version.getMajorVersion() == 1 && version.getMinorVersion() == 0) { LegacyObjectMetadata objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } ObjectMetadata objectName = null; while ((line = reader.readLine()) != null) { objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } 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 write(final InputStream in, final OutputStream out, boolean writeVersionHeader) throws IOException { checkNotNull(in); checkNotNull(out); final BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charsets.UTF_8)); String line; if (writeVersionHeader) { ObjectFileUtil.writeObjectFileVersion(out); } line = reader.readLine(); ObjectFileVersion version = null; if (line != null) { version = ObjectFileVersion.fromCharString(line); if (version.getMajorVersion() == 1 && version.getMinorVersion() == 0) { LegacyObjectMetadata objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } ObjectMetadata objectName = null; while ((line = reader.readLine()) != null) { objectName = getObjectFromCharString(version.getMajorVersion(), version.getMinorVersion(), line); out.write(objectName.toBytes()); } } 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);  }