@Test(expected = IllegalArgumentException.class) public void fromMetadataNegativeObjectSize() { LegacyObjectMetadata.fromMetadata(objectString(UUID.randomUUID()), -1, 0, (byte)-1, -1); }
public static LegacyObjectMetadata fromMetadata(final String objectName, final long objectSize, final int containerSuffix, final byte numLegalHolds, final int retentionPeriod) { checkNotNull(objectName); final int stringLength = 2 * OBJECT_NAME_SIZE; checkArgument(objectName.length() == stringLength, String.format("objectName length must be == %s", stringLength) + " [%s]", objectName.length()); checkArgument(objectSize >= 0, "objectSize must be >= 0 [%s]", objectSize); checkArgument(containerSuffix >= -1, "containerSuffix must be >= -1 [%s]", containerSuffix); checkArgument(numLegalHolds >= -1, "numLegalHolds must be >= -1 [%s]", numLegalHolds); checkArgument(retentionPeriod >= -2, "retentionPeriod must be >= -2 [%s]", retentionPeriod); final ByteBuffer objectBuffer = ByteBuffer.allocate(OBJECT_SIZE); objectBuffer.put(ENCODING.decode(objectName), 0, OBJECT_NAME_SIZE); objectBuffer.putLong(objectSize); objectBuffer.putInt(containerSuffix); objectBuffer.put(numLegalHolds); objectBuffer.putInt(retentionPeriod); return new LegacyObjectMetadata(objectBuffer); }
LegacyObjectMetadata implements ObjectMetadata { public static LegacyObjectMetadata fromMetadata(final String objectName, final long objectSize, final int containerSuffix, final byte numLegalHolds, final int retentionPeriod) { checkNotNull(objectName); final int stringLength = 2 * OBJECT_NAME_SIZE; checkArgument(objectName.length() == stringLength, String.format("objectName length must be == %s", stringLength) + " [%s]", objectName.length()); checkArgument(objectSize >= 0, "objectSize must be >= 0 [%s]", objectSize); checkArgument(containerSuffix >= -1, "containerSuffix must be >= -1 [%s]", containerSuffix); checkArgument(numLegalHolds >= -1, "numLegalHolds must be >= -1 [%s]", numLegalHolds); checkArgument(retentionPeriod >= -2, "retentionPeriod must be >= -2 [%s]", retentionPeriod); final ByteBuffer objectBuffer = ByteBuffer.allocate(OBJECT_SIZE); objectBuffer.put(ENCODING.decode(objectName), 0, OBJECT_NAME_SIZE); objectBuffer.putLong(objectSize); objectBuffer.putInt(containerSuffix); objectBuffer.put(numLegalHolds); objectBuffer.putInt(retentionPeriod); return new LegacyObjectMetadata(objectBuffer); } }
LegacyObjectMetadata implements ObjectMetadata { public static LegacyObjectMetadata fromMetadata(final String objectName, final long objectSize, final int containerSuffix, final byte numLegalHolds, final int retentionPeriod) { checkNotNull(objectName); final int stringLength = 2 * OBJECT_NAME_SIZE; checkArgument(objectName.length() == stringLength, String.format("objectName length must be == %s", stringLength) + " [%s]", objectName.length()); checkArgument(objectSize >= 0, "objectSize must be >= 0 [%s]", objectSize); checkArgument(containerSuffix >= -1, "containerSuffix must be >= -1 [%s]", containerSuffix); checkArgument(numLegalHolds >= -1, "numLegalHolds must be >= -1 [%s]", numLegalHolds); checkArgument(retentionPeriod >= -2, "retentionPeriod must be >= -2 [%s]", retentionPeriod); final ByteBuffer objectBuffer = ByteBuffer.allocate(OBJECT_SIZE); objectBuffer.put(ENCODING.decode(objectName), 0, OBJECT_NAME_SIZE); objectBuffer.putLong(objectSize); objectBuffer.putInt(containerSuffix); objectBuffer.put(numLegalHolds); objectBuffer.putInt(retentionPeriod); return new LegacyObjectMetadata(objectBuffer); } protected  LegacyObjectMetadata(final ByteBuffer objectBuffer); }
LegacyObjectMetadata implements ObjectMetadata { public static LegacyObjectMetadata fromMetadata(final String objectName, final long objectSize, final int containerSuffix, final byte numLegalHolds, final int retentionPeriod) { checkNotNull(objectName); final int stringLength = 2 * OBJECT_NAME_SIZE; checkArgument(objectName.length() == stringLength, String.format("objectName length must be == %s", stringLength) + " [%s]", objectName.length()); checkArgument(objectSize >= 0, "objectSize must be >= 0 [%s]", objectSize); checkArgument(containerSuffix >= -1, "containerSuffix must be >= -1 [%s]", containerSuffix); checkArgument(numLegalHolds >= -1, "numLegalHolds must be >= -1 [%s]", numLegalHolds); checkArgument(retentionPeriod >= -2, "retentionPeriod must be >= -2 [%s]", retentionPeriod); final ByteBuffer objectBuffer = ByteBuffer.allocate(OBJECT_SIZE); objectBuffer.put(ENCODING.decode(objectName), 0, OBJECT_NAME_SIZE); objectBuffer.putLong(objectSize); objectBuffer.putInt(containerSuffix); objectBuffer.put(numLegalHolds); objectBuffer.putInt(retentionPeriod); return new LegacyObjectMetadata(objectBuffer); } protected  LegacyObjectMetadata(final ByteBuffer objectBuffer); static LegacyObjectMetadata fromBytes(final byte[] objectBytes); static LegacyObjectMetadata fromMetadata(final String objectName, final long objectSize,
      final int containerSuffix, final byte numLegalHolds, final int retentionPeriod); @Override String getName(); @Override long getSize(); @Override int getContainerSuffix(); @Override int getNumberOfLegalHolds(); @Override int getRetention(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override int compareTo(final ObjectMetadata o); @Override byte[] toBytes(); @Override String toString(); }
LegacyObjectMetadata implements ObjectMetadata { public static LegacyObjectMetadata fromMetadata(final String objectName, final long objectSize, final int containerSuffix, final byte numLegalHolds, final int retentionPeriod) { checkNotNull(objectName); final int stringLength = 2 * OBJECT_NAME_SIZE; checkArgument(objectName.length() == stringLength, String.format("objectName length must be == %s", stringLength) + " [%s]", objectName.length()); checkArgument(objectSize >= 0, "objectSize must be >= 0 [%s]", objectSize); checkArgument(containerSuffix >= -1, "containerSuffix must be >= -1 [%s]", containerSuffix); checkArgument(numLegalHolds >= -1, "numLegalHolds must be >= -1 [%s]", numLegalHolds); checkArgument(retentionPeriod >= -2, "retentionPeriod must be >= -2 [%s]", retentionPeriod); final ByteBuffer objectBuffer = ByteBuffer.allocate(OBJECT_SIZE); objectBuffer.put(ENCODING.decode(objectName), 0, OBJECT_NAME_SIZE); objectBuffer.putLong(objectSize); objectBuffer.putInt(containerSuffix); objectBuffer.put(numLegalHolds); objectBuffer.putInt(retentionPeriod); return new LegacyObjectMetadata(objectBuffer); } protected  LegacyObjectMetadata(final ByteBuffer objectBuffer); static LegacyObjectMetadata fromBytes(final byte[] objectBytes); static LegacyObjectMetadata fromMetadata(final String objectName, final long objectSize,
      final int containerSuffix, final byte numLegalHolds, final int retentionPeriod); @Override String getName(); @Override long getSize(); @Override int getContainerSuffix(); @Override int getNumberOfLegalHolds(); @Override int getRetention(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override int compareTo(final ObjectMetadata o); @Override byte[] toBytes(); @Override String toString(); static final int OBJECT_NAME_SIZE; static final int OBJECT_SIZE_SIZE; static final int OBJECT_SUFFIX_SIZE; static final int OBJECT_LEGAL_HOLDS_SIZE; static final int OBJECT_RETENTION_SIZE; static final int OBJECT_SIZE; static final byte MAJOR_VERSION; static final byte MINOR_VERSION; }