/** * Assigns a byte array as the content and returns the handle * as a fluent convenience. * @param content the byte array * @return this handle */ public BytesHandle with(byte[] content) { set(content); return this; }
/** * Assigns a byte array as the content and returns the handle * as a fluent convenience. * @param content the byte array * @return this handle */ public BytesHandle with(byte[] content) { set(content); return this; }
/** * Initializes the handle with a byte array for the content. * @param content the byte array */ public BytesHandle(byte[] content) { this(); set(content); }
/** * Initializes the handle with a byte array for the content. * @param content the byte array */ public BytesHandle(byte[] content) { this(); set(content); }
contentHandle.set(bytes);
contentHandle.set(bytes);
@Test public void testWrite_ttl_FileHandle() throws Exception { File file = new File(datasource + "relative3.ttl"); FileInputStream fileinputstream = new FileInputStream(file); ByteArrayOutputStream byteoutputstream = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; // Get triples into bytes from file for (int readNum; (readNum = fileinputstream.read(buf)) != -1;) { byteoutputstream.write(buf, 0, readNum); } byte[] bytes = byteoutputstream.toByteArray(); fileinputstream.close(); byteoutputstream.close(); BytesHandle contentHandle = new BytesHandle(); contentHandle.set(bytes); // write triples in bytes to DB gmWriter.write("http://test.turtle.com/byteHandle", contentHandle.withMimetype(RDFMimeTypes.TURTLE)); BytesHandle byteHandle = gmWriter.read("http://test.turtle.com/byteHandle", new BytesHandle().withMimetype(RDFMimeTypes.TURTLE)); byte[] readInBytes = byteHandle.get(); String readInString = new String(readInBytes); assertTrue("Did not insert document or inserted empty doc", readInString.contains("#relativeIRI")); }
handle.set(contentInByte);
@Test public void testWrite_n3_BytesHandle() throws Exception { File file = new File(datasource + "relative7.n3"); FileInputStream fileinputstream = new FileInputStream(file); ByteArrayOutputStream byteoutputstream = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; // Get triples into bytes from file for (int readNum; (readNum = fileinputstream.read(buf)) != -1;) { byteoutputstream.write(buf, 0, readNum); } byte[] bytes = byteoutputstream.toByteArray(); fileinputstream.close(); byteoutputstream.close(); BytesHandle contentHandle = new BytesHandle(); contentHandle.set(bytes); // write triples in bytes to DB gmWriter.write("http://test.n3.com/byte", contentHandle.withMimetype(RDFMimeTypes.N3)); InputStreamHandle read = gmWriter.read("http://test.n3.com/byte", new InputStreamHandle().withMimetype(RDFMimeTypes.N3)); InputStream fileRead = read.get(); String readContent = convertInputStreamToString(fileRead); assertTrue("Did not find expected content after inserting the triples:: Found: " + readContent, readContent.contains("/publications/journals/Journal1/1940")); read.close(); }