@Override public Blob createBlob(InputStream stream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(stream)); } finally { stream.close(); } }
@NotNull @Override public InputStream getNewStream() { accessCount++; return super.getNewStream(); } }
/** * @return An instance of {@link ArrayBasedBlob}. */ @Override public ArrayBasedBlob createBlob(InputStream inputStream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(inputStream)); } finally { inputStream.close(); } }
@NotNull @Override public InputStream getNewStream() { if (corruptLength){ return super.getNewStream(); } throw new UnsupportedOperationException(); }
@Override public Blob createBlob(InputStream stream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(stream)); } finally { stream.close(); } }
@NotNull @Override public InputStream getNewStream() { checkState(allowAccessToContent, "Cannot access the stream"); return super.getNewStream(); } }
/** * @return An instance of {@link ArrayBasedBlob}. */ @Override public ArrayBasedBlob createBlob(InputStream inputStream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(inputStream)); } finally { inputStream.close(); } }
@NotNull @Override public InputStream getNewStream() { accessCount++; stream = new CountingInputStream(super.getNewStream()); return stream; }
/** * Create a {@code PropertyState} from an array of bytes. * @param name The name of the property state * @param value The value of the property state * @return The new property state of type {@link Type#BINARY} */ public static PropertyState binaryProperty( @Nonnull String name, @Nonnull byte[] value) { return new BinaryPropertyState( name, new ArrayBasedBlob(checkNotNull(value))); }
/** * Create a {@code PropertyState} from an array of bytes. * @param name The name of the property state * @param value The value of the property state * @return The new property state of type {@link Type#BINARY} */ public static PropertyState binaryProperty( @NotNull String name, @NotNull byte[] value) { return new BinaryPropertyState( name, new ArrayBasedBlob(checkNotNull(value))); }
@Override public Blob deserialize(String value) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); StringReader reader = new StringReader(value); try { Base64.decode(reader, baos); } catch (IOException e) { throw new RuntimeException(e); } return new ArrayBasedBlob(baos.toByteArray()); } }
/** * Create a multi valued {@code PropertyState} from a list of byte arrays. * @param name The name of the property state * @param values The values of the property state * @return The new property state of type {@link Type#BINARIES} */ public static PropertyState binaryPropertyFromArray(String name, Iterable<byte[]> values) { List<Blob> blobs = Lists.newArrayList(); for (byte[] data : values) { blobs.add(new ArrayBasedBlob(data)); } return new MultiBinaryPropertyState(name, blobs); }
@Override public Blob deserialize(String value) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); StringReader reader = new StringReader(value); try { Base64.decode(reader, baos); } catch (IOException e) { throw new RuntimeException(e); } return new ArrayBasedBlob(baos.toByteArray()); } }
/** * Create a multi valued {@code PropertyState} from a list of byte arrays. * @param name The name of the property state * @param values The values of the property state * @return The new property state of type {@link Type#BINARIES} */ public static PropertyState binaryPropertyFromArray(String name, Iterable<byte[]> values) { List<Blob> blobs = Lists.newArrayList(); for (byte[] data : values) { blobs.add(new ArrayBasedBlob(data)); } return new MultiBinaryPropertyState(name, blobs); }
private static Blob createBlob(NodeStore nodeStore) throws IOException { byte[] buffer = new byte[LENGTH]; RANDOM.nextBytes(buffer); return new ArrayBasedBlob(buffer); }
private static Blob createRandomBlob(int size) { byte[] bytes = new byte[size]; new Random().nextBytes(bytes); return new ArrayBasedBlob(bytes); }
private Tree createFileNode(Tree tree, String name, String content, String mimeType){ return createFileNode(tree, name, new ArrayBasedBlob(content.getBytes()), mimeType); }
private Blob createBlob(int length) { return new ArrayBasedBlob(randomBytes(length)); }
@Test public void inMemoryBlob() throws Exception{ Blob b = new ArrayBasedBlob("hello world".getBytes()); String value = serializer.serialize(b); Blob b2 = serializer.deserialize(value); assertTrue(AbstractBlob.equal(b, b2)); }