javax.jcr.Binary.read()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中javax.jcr.Binary.read()方法的一些代码示例,展示了Binary.read()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binary.read()方法的具体详情如下:
包路径:javax.jcr.Binary
类名称:Binary
方法名:read

Binary.read介绍

[英]Reads successive bytes from the specified position in this Binary into the passed byte array until either the byte array is full or the end of the Binary is encountered.

If #dispose() has been called on this Binary object, then this method will throw the runtime exception java.lang.IllegalStateException.
[中]将此Binary中指定的position中的连续字节读取到传递的字节数组中,直到字节数组已满或遇到Binary的结尾。
如果对这个Binary对象调用了#dispose(),那么这个方法将抛出java运行时异常。非法国家例外。

代码示例

代码示例来源:origin: org.onehippo.cms7/hippo-cms-api

@Override
public int read(final byte[] b, final long position) throws IOException, RepositoryException {
  return binary.read(b, position);
}

代码示例来源:origin: ModeShape/modeshape

@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);
  }
}

代码示例来源:origin: org.modeshape/modeshape-jdbc-local

@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);
  }
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons

/**
 * 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;
}

代码示例来源:origin: apache/jackrabbit

/**
 * 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;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

/**
 * 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;
}

代码示例来源:origin: apache/jackrabbit

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();
      }
    }
  }
}

代码示例来源:origin: apache/jackrabbit

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]);

代码示例来源:origin: apache/jackrabbit

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();
      }
    }
  }
}

代码示例来源:origin: apache/jackrabbit

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"));
}

代码示例来源:origin: org.teiid.modeshape/teiid-modeshape-sequencer-dataservice

final Binary value = content.getProperty( JcrConstants.JCR_DATA ).getBinary();
final byte[] data = new byte[ ( int )value.getSize() ];
value.read( data, 0 );

代码示例来源:origin: org.teiid.modeshape/teiid-modeshape-sequencer-dataservice

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 );

代码示例来源:origin: apache/jackrabbit

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"));
}

相关文章