@Override public int read(final byte[] b, final long position) throws IOException, RepositoryException { return binary.read(b, position); }
@Override public byte[] getBytes( long pos, int length ) throws SQLException { try { byte[] data = new byte[length]; int numRead = 0; try { numRead = binary.read(data, pos); } finally { binary.dispose(); } // We may have read less than the desired length ... if (numRead < length) { // create a shortened array ... byte[] shortData = new byte[numRead]; System.arraycopy(data, 0, shortData, 0, numRead); data = shortData; } return data; } catch (Exception e) { throw new SQLException(e); } }
@Override public byte[] getBytes( long pos, int length ) throws SQLException { try { byte[] data = new byte[length]; int numRead = 0; try { numRead = binary.read(data, pos); } finally { binary.dispose(); } // We may have read less than the desired length ... if (numRead < length) { // create a shortened array ... byte[] shortData = new byte[numRead]; System.arraycopy(data, 0, shortData, 0, numRead); data = shortData; } return data; } catch (Exception e) { throw new SQLException(e); } }
/** * Gets the string representation of this binary value. * * @return string representation of this binary value. * * @throws javax.jcr.ValueFormatException * @throws javax.jcr.RepositoryException if another error occurs */ public String getInternalString() throws ValueFormatException, RepositoryException { // build text value if necessary if (text == null) { try { byte[] bytes = new byte[(int) bin.getSize()]; bin.read(bytes, 0); text = new String(bytes, DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new RepositoryException(DEFAULT_ENCODING + " not supported on this platform", e); } catch (IOException e) { throw new RepositoryException("failed to retrieve binary data", e); } } return text; }
/** * Gets the string representation of this binary value. * * @return string representation of this binary value. * * @throws javax.jcr.ValueFormatException * @throws javax.jcr.RepositoryException if another error occurs */ public String getInternalString() throws ValueFormatException, RepositoryException { // build text value if necessary if (text == null) { try { byte[] bytes = new byte[(int) bin.getSize()]; bin.read(bytes, 0); text = new String(bytes, DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new RepositoryException(DEFAULT_ENCODING + " not supported on this platform", e); } catch (IOException e) { throw new RepositoryException("failed to retrieve binary data", e); } } return text; }
/** * Gets the string representation of this binary value. * * @return string representation of this binary value. * * @throws javax.jcr.ValueFormatException * @throws javax.jcr.RepositoryException if another error occurs */ public String getInternalString() throws ValueFormatException, RepositoryException { // build text value if necessary if (text == null) { try { byte[] bytes = new byte[(int) bin.getSize()]; bin.read(bytes, 0); text = new String(bytes, DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new RepositoryException(DEFAULT_ENCODING + " not supported on this platform", e); } catch (IOException e) { throw new RepositoryException("failed to retrieve binary data", e); } } return text; }
protected void checkProperty(Property prop) throws Exception { for (int i = 0; i < 3; i++) { Binary b = prop.getBinary(); try { //System.out.println(b.getClass() + ": " + System.identityHashCode(b)); b.read(new byte[1], 0); } finally { b.dispose(); } } } }
assertEquals("reading behind EOF must return -1", -1, bin.read(buf, bin.getSize())); for (int cnt, pos = 0; (cnt = bin.read(buf, pos)) > 0; pos += cnt) { out.write(buf, 0, cnt); assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf, 0)); assertEquals("unexpected result of Value.getBinary.read()", content[0], buf[0]); if (content.length > 0) { assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf, content.length - 1)); assertEquals("unexpected result of Value.getBinary.read()", content[content.length - 1], buf[0]); assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf, 0)); assertEquals("unexpected result of Value.getBinary.read()", content[0], buf[0]);
protected void checkBinary(Property p) throws Exception { for (int i = 0; i < 3; i++) { Binary bin = p.getBinary(); try { //System.out.println(bin.getClass() + "@" + System.identityHashCode(bin)); bin.read(new byte[1], 0); } finally { bin.dispose(); } } } }
public void testGetBinary() throws RepositoryException, IOException { Binary binary = prop.getBinary(); byte[] bytes = new byte[(int) binary.getSize()]; binary.read(bytes, 0); binary.dispose(); assertEquals(prop.getString(), new String(bytes, "UTF-8")); }
final Binary value = content.getProperty( JcrConstants.JCR_DATA ).getBinary(); final byte[] data = new byte[ ( int )value.getSize() ]; value.read( data, 0 );
final Binary value = content.getProperty( JcrConstants.JCR_DATA ).getBinary(); final byte[] data = new byte[ ( int )value.getSize() ]; value.read( data, 0 ); entryPaths.add( entry.getPath() ); contents.add( data );
public void testGetBinaryFromValue() throws RepositoryException, IOException { Value v = superuser.getValueFactory().createValue("/a/b/c", PropertyType.PATH); Binary binary = v.getBinary(); byte[] bytes = new byte[(int) binary.getSize()]; binary.read(bytes, 0); binary.dispose(); assertEquals(prop.getString(), new String(bytes, "UTF-8")); }