@Override public Blob createBlob(InputStream stream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(stream)); } finally { stream.close(); } }
/** * @return An instance of {@link ArrayBasedBlob}. */ @Override public ArrayBasedBlob createBlob(InputStream inputStream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(inputStream)); } finally { inputStream.close(); } }
@Override public Blob createBlob(InputStream stream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(stream)); } finally { stream.close(); } }
/** * @return An instance of {@link ArrayBasedBlob}. */ @Override public ArrayBasedBlob createBlob(InputStream inputStream) throws IOException { try { return new ArrayBasedBlob(ByteStreams.toByteArray(inputStream)); } finally { inputStream.close(); } }
/** * 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()); } }
@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); }
@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)); }
@Test public void binaryProps() throws Exception{ NodeBuilder builder = store.getRoot().builder(); builder.child("a").setProperty("foo", new ArrayBasedBlob("hello".getBytes())); store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY); when(pathService.getIndexPaths()).thenReturn(Lists.newArrayList("/a")); String json = getJSON(); IndexDefinitionUpdater updater = new IndexDefinitionUpdater(json); assertTrue(updater.getIndexPaths().contains("/a")); }
@Test public void blobs() throws Exception{ int maxInlineSize = 100; FSBlobSerializer serializer = new FSBlobSerializer(folder.getRoot(), maxInlineSize); String data = Strings.repeat("x", maxInlineSize * 10); Blob b = new ArrayBasedBlob(data.getBytes(UTF_8)); String id = serializer.serialize(b); Blob b2 = serializer.deserialize(id); assertTrue(AbstractBlob.equal(b, b2)); }
@Test public void longReferencesShouldHaveBlobIdType() throws Exception { try (FileStore ss = newFileStore(new LongIdMappingBlobStore())) { SegmentWriter sw = defaultSegmentWriterBuilder("test").build(ss); byte[] content = new byte[Segment.MEDIUM_LIMIT + 1]; SegmentBlob sb = new SegmentBlob(ss.getBlobStore(), sw.writeBlob(new ArrayBasedBlob(content))); assertRecordTypeEquals(sb, RecordType.BLOB_ID); } }
@Test public void shortReferencesShouldHaveBlobIdType() throws Exception { try (FileStore ss = newFileStore(new ShortIdMappingBlobStore())) { SegmentWriter sw = defaultSegmentWriterBuilder("test").build(ss); byte[] content = new byte[Segment.MEDIUM_LIMIT + 1]; SegmentBlob sb = new SegmentBlob(ss.getBlobStore(), sw.writeBlob(new ArrayBasedBlob(content))); assertRecordTypeEquals(sb, RecordType.BLOB_ID); } }
private NodeState corruptIndex(String indexPath) { NodeBuilder dir = TestUtil.child(builder, PathUtils.concat(indexPath, ":data")); for (String name : dir.getChildNodeNames()){ if (!"segments.gen".equals(name)){ dir.getChildNode(name).setProperty(PropertyStates.createProperty("jcr:data", Collections .singletonList(new ArrayBasedBlob("foo".getBytes())), Type.BINARIES)); } } TestUtil.child(builder, PathUtils.concat(indexPath, IndexDefinition.STATUS_NODE)).setProperty("foo", "bar"); return builder.getNodeState(); }
@Test public void testCloseOnOriginalIndexInput() throws Exception { Directory dir = createDir(builder, false, "/foo"); NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt"); int dataSize = 1024; List<? super Blob> blobs = new ArrayList<Blob>(dataSize); for (int i = 0; i < dataSize; i++) { blobs.add(new ArrayBasedBlob(new byte[0])); } file.setProperty(PropertyStates.createProperty("jcr:data", blobs, Type.BINARIES)); IndexInput input = dir.openInput("test.txt", IOContext.DEFAULT); input.close(); assertClosed(input); }
@Test public void blobStoreBlob() throws Exception{ Blob b = new ArrayBasedBlob("hello world".getBytes()); String value = blobStore.writeBlob(b.getNewStream()); String serValue = serializer.serialize(new BlobStoreBlob(blobStore, value)); Blob b2 = serializer.deserialize(serValue); assertTrue(AbstractBlob.equal(b, b2)); }
@Test public void cacheEnabledNonIdBlob() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); Blob b = new ArrayBasedBlob("hello".getBytes()); String text = cache.get("/a", "foo", b, false); assertNull(text); cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello")); text = cache.get("/a", "foo", b, false); assertNull(text); }