/** ByteBuffer to String */ public static String byteBufferToString(ByteBuffer bb) { byte[] b = new byte[bb.remaining()] ; bb.get(b) ; return StrUtils.fromUTF8bytes(b) ; }
/** ByteBuffer to String */ public static String byteBufferToString(ByteBuffer bb) { byte[] b = new byte[bb.remaining()] ; bb.get(b) ; return StrUtils.fromUTF8bytes(b) ; }
public static String zkFetchStr(CuratorFramework client, String path) { byte[] x = zkFetch(client, path); if ( x == null ) return null; return StrUtils.fromUTF8bytes(x); }
/** Read the file to get a process id */ private int readProcessId(int dft) throws IOException { ByteBuffer bb = ByteBuffer.allocate(128); fileChannel.position(0); int len = fileChannel.read(bb); fileChannel.position(0); if ( len == 0 ) return dft; if ( len == 128 ) // Too much. return dft; // Bug in Jena 3.3.0 //byte[] b = ByteBufferLib.bb2array(bb, 0, len); bb.flip(); byte[] b = new byte[len]; bb.get(b); String pidStr = StrUtils.fromUTF8bytes(b); // Remove all leading and trailing (vertical and horizontal) whitespace. pidStr = pidStr.replaceAll("[\\s\\t\\n\\r]+$", ""); pidStr = pidStr.replaceAll("^[\\s\\t\\n\\r]+", ""); try { // Process id. return Integer.parseInt(pidStr); } catch (NumberFormatException ex) { ex.printStackTrace(); Log.warn(this, "Bad process id: file='"+filepath+"': read='"+pidStr+"'"); return dft; } }
/** Generate a string in the specified language/syntax for a SPARQL result set. * @param resultSet * @param lang */ public static String asString(ResultSet resultSet, Lang lang) { Objects.requireNonNull(lang); ByteArrayOutputStream output = new ByteArrayOutputStream(1000); ResultsWriter.create() .lang(lang) .write(output, resultSet); return StrUtils.fromUTF8bytes(output.toByteArray()); }
/** Read the file to get a process id */ private int readProcessId(int dft) throws IOException { ByteBuffer bb = ByteBuffer.allocate(128); fileChannel.position(0); int len = fileChannel.read(bb); fileChannel.position(0); if ( len == 0 ) return dft; if ( len == 128 ) // Too much. return dft; // Bug in Jena 3.3.0 //byte[] b = ByteBufferLib.bb2array(bb, 0, len); bb.flip(); byte[] b = new byte[len]; bb.get(b); String pidStr = StrUtils.fromUTF8bytes(b); // Remove all leadign and trailing (vertical and horizontal) whitespace. pidStr = pidStr.replaceAll("[\\s\\t\\n\\r]+$", ""); pidStr = pidStr.replaceAll("^[\\s\\t\\n\\r]+", ""); try { // Process id. return Integer.parseInt(pidStr); } catch (NumberFormatException ex) { ex.printStackTrace(); Log.warn(this, "Bad process id: file='"+filepath+"': read='"+pidStr+"'"); return dft; } }
/** Generate a string in the specified language/syntax for a SPARQL boolean result. * @param result * @param lang */ public static String asString(boolean result, Lang lang) { Objects.requireNonNull(lang); ByteArrayOutputStream output = new ByteArrayOutputStream(1000); ResultsWriter.create() .lang(lang) .build() .write(output, result); return StrUtils.fromUTF8bytes(output.toByteArray()); }
/** Copy from the temporary file to the real file */ private void append() { // We could write directly to the real file if: // we record the truncate point needed for an abort // manage partial final writes // deny the existence of nodes after the transaction mark. // Later - stay simple for now. // Truncate/position the ObjectFile. base.reposition(otherAllocOffset) ; Iterator<Pair<Long, ByteBuffer>> iter = transObjects.all() ; for ( ; iter.hasNext() ; ) { Pair<Long, ByteBuffer> p = iter.next() ; String s = StrUtils.fromUTF8bytes(p.getRight().array()) ; long x = base.write(p.getRight()) ; if ( p.getLeft()+otherAllocOffset != x ) throw new FileException("Expected id of "+(p.getLeft()+otherAllocOffset)+", got an id of "+x) ; } }
private static void contains(ObjectFile f, String... contents) { Iterator<Pair<Long, ByteBuffer>> iter = f.all() ; for ( String s : contents ) { assertTrue(iter.hasNext()) ; Pair<Long, ByteBuffer> p = iter.next() ; String s2 = StrUtils.fromUTF8bytes(p.cdr().array()) ; assertEquals(s, s2) ; } assertFalse(iter.hasNext()) ; }
private static void contains(ObjectFile f, String... contents) { Iterator<Pair<Long, ByteBuffer>> iter = f.all() ; for ( String s : contents ) { assertTrue(iter.hasNext()) ; Pair<Long, ByteBuffer> p = iter.next() ; String s2 = StrUtils.fromUTF8bytes(p.cdr().array()) ; assertEquals(s, s2) ; } assertFalse(iter.hasNext()) ; }
private static void contains(ObjectFile f, String... contents) { Iterator<Pair<Long, ByteBuffer>> iter = f.all() ; for ( String s : contents ) { assertTrue(iter.hasNext()) ; Pair<Long, ByteBuffer> p = iter.next() ; String s2 = StrUtils.fromUTF8bytes(p.cdr().array()) ; assertEquals(s, s2) ; } assertFalse(iter.hasNext()) ; }
private static void contains(ObjectFile f, String... contents) { Iterator<Pair<Long, ByteBuffer>> iter = f.all() ; for ( String s : contents ) { assertTrue(iter.hasNext()) ; Pair<Long, ByteBuffer> p = iter.next() ; String s2 = StrUtils.fromUTF8bytes(p.cdr().array()) ; assertEquals(s, s2) ; } assertFalse(iter.hasNext()) ; }
@Test public void rdfwriter_5() { ByteArrayOutputStream bout = new ByteArrayOutputStream(); RDFWriter.create() .source(graph) .lang(Lang.NT) .output(bout); String s = StrUtils.fromUTF8bytes(bout.toByteArray()); assertTrue(s.contains("example/s")); }
private static String readOne(Transactional transactional, TransBinaryDataFile transBinaryFile, long posn) { return Txn.calculateRead(transactional, ()->{ byte[] lenBytes = new byte[4] ; long x = posn ; int got = transBinaryFile.read(x, lenBytes) ; x += got ; int len = Bytes.getInt(lenBytes) ; byte[] bytes = new byte[len] ; got = transBinaryFile.read(x, bytes) ; x += got ; return StrUtils.fromUTF8bytes(bytes) ; }) ; }
private static String readOne(Transactional transactional, TransBinaryDataFile transBinaryFile, long posn) { return Txn.calculateRead(transactional, ()->{ byte[] lenBytes = new byte[4] ; long x = posn ; int got = transBinaryFile.read(x, lenBytes) ; x += got ; int len = Bytes.getInt(lenBytes) ; byte[] bytes = new byte[len] ; got = transBinaryFile.read(x, bytes) ; x += got ; return StrUtils.fromUTF8bytes(bytes) ; }) ; }
String s = StrUtils.fromUTF8bytes(out.toByteArray()) ;
private static String readOne(Transactional transactional, TransBinaryDataFile transBinaryFile, long posn) { return Txn.calculateRead(transactional, ()->{ byte[] lenBytes = new byte[4] ; long x = posn ; int got = transBinaryFile.read(x, lenBytes) ; x += got ; int len = Bytes.getInt(lenBytes) ; byte[] bytes = new byte[len] ; got = transBinaryFile.read(x, bytes) ; x += got ; return StrUtils.fromUTF8bytes(bytes) ; }) ; }
String s = StrUtils.fromUTF8bytes(out.toByteArray()) ; @SuppressWarnings("deprecation") Dataset ds2 = DatasetFactory.createMem() ;