org.modeshape.common.util.IoUtil.readBytes()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(143)

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

IoUtil.readBytes介绍

[英]Read and return the entire contents of the supplied File.
[中]读取并返回所提供文件的全部内容。

代码示例

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

/**
 * {@inheritDoc}
 * 
 * @see org.modeshape.graph.property.Binary#getBytes()
 */
public byte[] getBytes() {
  try {
    return IoUtil.readBytes(file);
  } catch (IOException e) {
    throw new IoException(e);
  }
}

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

public InMemoryTestBinary( InputStream is ) throws IOException {
  this(IoUtil.readBytes(is));
}

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

/**
 * {@inheritDoc}
 * 
 * @see org.modeshape.graph.property.BinaryFactory#create(java.io.File)
 */
public Binary create( File file ) throws ValueFormatException, IoException {
  if (file == null) return null;
  if (!file.canRead()) return null;
  if (!file.isFile()) return null;
  try {
    byte[] value = IoUtil.readBytes(file);
    return create(value);
  } catch (IOException err) {
    throw new IoException(GraphI18n.errorConvertingIo.text(file, Binary.class.getSimpleName()), err);
  }
}

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

/**
 * {@inheritDoc}
 */
public Binary create( InputStream stream,
           long approximateLength ) throws IoException {
  if (stream == null) return null;
  try {
    byte[] value = IoUtil.readBytes(stream);
    return create(value);
  } catch (IOException err) {
    throw new IoException(GraphI18n.errorConvertingIo.text(InputStream.class.getSimpleName(),
                                Binary.class.getSimpleName()), err);
  }
}

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

protected void assertFileContains( Projection projection,
                  String filePath,
                  InputStream expectedContent ) throws IOException {
  assertFileContains(projection, filePath, IoUtil.readBytes(expectedContent));
}

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

protected void assertBinaryContains( Binary binaryValue,
                   byte[] expectedContent ) throws IOException, RepositoryException {
  byte[] actual = IoUtil.readBytes(binaryValue.getStream());
  assertThat(actual, is(expectedContent));
}

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

protected void assertFileContains( Projection projection,
                  String filePath,
                  byte[] expectedContent ) throws IOException {
  File contentFile = projection.getTestFile(filePath);
  assertThat(contentFile.exists(), is(true));
  byte[] actual = IoUtil.readBytes(contentFile);
  assertThat(actual, is(expectedContent));
}

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

@Test
public void readBytesShouldReturnEmptyByteArrayForNullInputStream() throws Exception {
  assertThat(IoUtil.readBytes((InputStream)null), is(new byte[] {}));
}

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

public BinaryContains( BinaryValue expectedContent ) {
  try {
    this.expectedContent = IoUtil.readBytes(expectedContent.getStream());
  } catch (RepositoryException e) {
    throw new AssertionFailedError(e.getMessage());
  } catch (IOException e) {
    throw new AssertionFailedError(e.getMessage());
  } finally {
    expectedContent.dispose();
  }
}

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

private void storeBinaryAndAssert( byte[] data,
                  String nodeName ) throws RepositoryException, IOException {
  InputStream stream = storeBinaryProperty(data, nodeName);
  byte[] storedData = IoUtil.readBytes(stream);
  assertArrayEquals("Data retrieved does not match data stored", data, storedData);
}

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

@Test
public void shouldProvideInputStreamToContent() throws Exception {
  InputStream stream = binary.getStream();
  byte[] actual = IoUtil.readBytes(stream); // closes the stream
  assertThat(actual.length, is(validByteArrayContent.length));
  for (int i = 0, len = actual.length; i != len; ++i) {
    assertThat(actual[i], is(validByteArrayContent[i]));
  }
}

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

@Test
public void shouldProvideInputStreamToContent() throws IOException {
  InputStream stream = binary.getStream();
  byte[] actual = IoUtil.readBytes(stream); // closes the stream
  assertThat(actual.length, is(validByteArrayContent.length));
  for (int i = 0, len = actual.length; i != len; ++i) {
    assertThat(actual[i], is(validByteArrayContent[i]));
  }
}

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

@Test
  @FixFor("MODE-2413")
  public void shouldSupportReadingFromSelfClosingInputStream() throws Exception {
    byte[] buffer = new byte[1024];
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    URL resource = getClass().getResource("simple.json");
    try (Base64.InputStream is = new Base64.InputStream(new SelfClosingInputStream(resource.openStream()), Base64.ENCODE)) {
      int read;
      while ((read = is.read(buffer, 0, buffer.length)) != -1) {
        bos.write(buffer, 0, read);
      }                        
    }
    // until Java 8, use this....
    String expectedString = DatatypeConverter.printBase64Binary(IoUtil.readBytes(resource.openStream()));
    assertEquals("Incorrect Base64 encoding", expectedString, new String(bos.toByteArray()));
  }
}

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

@Test
public void shouldCallGetBinaryUsingColmnIndex() throws SQLException, IOException {
  int col = getColumnTypeLoc(TestUtil.BINARY);
  for (int i = 0; i < TestUtil.TUPLES.size(); i++) {
    assertThat(resultSet.next(), is(true));
    Object[] tuple = TestUtil.TUPLES.get(i);
    // need to increment because ResultSet is 1 based.
    assertThat(IoUtil.readBytes(resultSet.getBinaryStream(col + 1)), is(tuple[col]));
  }
}

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

@Test
public void shouldCallGetBinaryUsingColumnName() throws SQLException, IOException {
  int col = getColumnTypeLoc(TestUtil.BINARY);
  for (int i = 0; i < TestUtil.TUPLES.size(); i++) {
    assertThat(resultSet.next(), is(true));
    Object[] tuple = TestUtil.TUPLES.get(i);
    assertThat(IoUtil.readBytes(resultSet.getBinaryStream(TestUtil.COLUMN_NAMES[col])), is(tuple[col]));
  }
}

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

@Test
public void shouldCreateFile() throws Exception {
  String folderUri = resourceUri(testFolder());
  sardine.createDirectory(folderUri);
  InputStream fileStream = getClass().getClassLoader().getResourceAsStream("textfile.txt");
  assertNotNull(fileStream);
  String fileUri = folderUri + "/testFile" + UUID.randomUUID().toString();
  sardine.put(fileUri, fileStream);
  assertTrue(sardine.exists(fileUri));
  DavResource file = getResourceAtURI(fileUri);
  byte[] fileBytes = IoUtil.readBytes(getClass().getClassLoader().getResourceAsStream("textfile.txt"));
  assertEquals(fileBytes.length, file.getContentLength().longValue());
}

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

@Test
public void shouldPersistContentIntoTheDefaultStore() throws BinaryStoreException, IOException {
  byte[] content = randomContent();
  BinaryValue v = store.storeValue(new ByteArrayInputStream(content), false);
  InputStream is = store.getInputStream(v.getKey());
  byte[] storeContent = IoUtil.readBytes(is);
  InputStream is1 = defaultStore.getInputStream(v.getKey());
  byte[] defaultStoreContent = IoUtil.readBytes(is1);
  assertArrayEquals(content, storeContent);
  assertArrayEquals(content, defaultStoreContent);
}

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

@Test
public void shouldLookInAllBinaryStoresForAKey() throws BinaryStoreException, IOException {
  byte[] content = randomContent();
  BinaryValue v = alternativeStore.storeValue(new ByteArrayInputStream(content), false);
  InputStream is = store.getInputStream(v.getKey());
  byte[] storedContent = IoUtil.readBytes(is);
  assertArrayEquals(content, storedContent);
  assertThat(store.hasBinary(v.getKey()), is(true));
}

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

@FixFor( "MODE-1308" )
@Test
public void shouldSupportAnyBinaryImplementation() throws Exception {
  final String stringValue = "This is the string stringValue";
  Binary customBinary = createCustomBinary(stringValue);
  JcrValue jcrValue = new JcrValue(factories, PropertyType.BINARY, customBinary);
  org.modeshape.jcr.value.BinaryValue actualValue = jcrValue.getBinary();
  assertNotNull(actualValue);
  byte[] actualBytes = IoUtil.readBytes(actualValue.getStream());
  assertArrayEquals(stringValue.getBytes(), actualBytes);
}

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

private BinaryValue storeAndValidate( BinaryKey key,
                   byte[] data ) throws BinaryStoreException, IOException {
  BinaryValue res = getBinaryStore().storeValue(new ByteArrayInputStream(data), false);
  assertNotNull(res);
  assertEquals(key, res.getKey());
  assertEquals(data.length, res.getSize());
  InputStream inputStream = getBinaryStore().getInputStream(key);
  byte[] content = IoUtil.readBytes(inputStream);
  assertArrayEquals(data, content);
  BinaryKey currentKey = BinaryKey.keyFor(content);
  assertEquals(key, currentKey);
  return res;
}

相关文章

微信公众号

最新文章

更多