org.apache.commons.io.input.CharSequenceInputStream Java Examples

The following examples show how to use org.apache.commons.io.input.CharSequenceInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MCRContentStoreTestCase.java    From mycore with GNU General Public License v3.0 7 votes vote down vote up
@Test
public void testMD5CopyCommand() throws IOException {
    MCRObjectID derId = MCRObjectID.getInstance("MCR_derivate_00000003");
    String fileName = "hallo.txt";
    MCRPath filePath = MCRPath.getPath(derId.toString(), fileName);
    Files.createFile(filePath);
    try (InputStream is = new CharSequenceInputStream("Hello World!", StandardCharsets.UTF_8)) {
        Files.copy(is, filePath, StandardCopyOption.REPLACE_EXISTING);
    }
    startNewTransaction();
    MCRFileAttributes attrs = Files.readAttributes(filePath, MCRFileAttributes.class);
    MCRCStoreIFS2 ifs2 = (MCRCStoreIFS2) MCRContentStoreFactory.getStore("IFS2");
    MCRFileCollection fileCollection = ifs2.getIFS2FileCollection(derId);
    org.mycore.datamodel.ifs2.MCRFile file2 = (org.mycore.datamodel.ifs2.MCRFile) fileCollection.getChild(fileName);
    Assert.assertEquals("MD5 mismatch.", attrs.md5sum(), file2.getMD5());
    file2.setMD5("invalid");
    file2 = (org.mycore.datamodel.ifs2.MCRFile) fileCollection.getChild(fileName);
    Assert.assertNotEquals("MD5 was not updated.", attrs.md5sum(), file2.getMD5());
    MCRIFSCommands.copyMD5ToIFS2();
    file2 = (org.mycore.datamodel.ifs2.MCRFile) fileCollection.getChild(fileName);
    Assert.assertEquals("MD5 mismatch.", attrs.md5sum(), file2.getMD5());
}
 
Example #2
Source File: MCRContentStoreTestCase.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void md5Sum() throws IOException {
    MCRObjectID derId = MCRObjectID.getInstance("MCR_derivate_00000002");
    String fileName = "hallo.txt";
    MCRPath filePath = MCRPath.getPath(derId.toString(), fileName);
    Files.createFile(filePath);
    try (InputStream is = new CharSequenceInputStream("Hello World!", StandardCharsets.UTF_8)) {
        Files.copy(is, filePath, StandardCopyOption.REPLACE_EXISTING);
    }
    startNewTransaction();
    MCRFileAttributes attrs = Files.readAttributes(filePath, MCRFileAttributes.class);
    MCRCStoreIFS2 ifs2 = (MCRCStoreIFS2) MCRContentStoreFactory.getStore("IFS2");
    MCRFileCollection fileCollection = ifs2.getIFS2FileCollection(derId);
    org.mycore.datamodel.ifs2.MCRFile file2 = (org.mycore.datamodel.ifs2.MCRFile) fileCollection.getChild(fileName);
    Assert.assertEquals("MD5 mismatch.", attrs.md5sum(), file2.getMD5());
}
 
Example #3
Source File: StreamUtilTest.java    From smartsheet-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadBytesFromStream() throws Exception {
    final String testString = "fuzzy wuzzy was a bear; fuzzy wuzzy had no hair...";
    final byte[] testBytes = testString.getBytes("UTF-8");
    final InputStream inputStream = new CharSequenceInputStream(testString, "UTF-8");
    final ByteArrayOutputStream copyStream = new ByteArrayOutputStream();

    // this takes what was in inputStream, copies it into copyStream, and either resets inputStream (if supported)
    // or returns a new stream around the bytes read
    final InputStream backupStream = StreamUtil.cloneContent(inputStream, StreamUtil.ONE_MB, copyStream);
    if (backupStream == inputStream) {
        System.out.println("same stream returned (reset)");
        // verify readBytesFromStream gets everything from the inputStream (it also verifies cloneContent resets the source)
        byte[] streamBytes = StreamUtil.readBytesFromStream(inputStream);
        Assert.assertArrayEquals(testBytes, streamBytes); // it's all US-ASCII so it should match UTF-8 bytes
    } else {
        System.out.println("new stream returned");
        byte[] backupBytes = StreamUtil.readBytesFromStream(backupStream);
        Assert.assertArrayEquals(testBytes, backupBytes);
    }

    Assert.assertArrayEquals(testBytes, copyStream.toByteArray());
}
 
Example #4
Source File: TestHelper.java    From git-as-svn with GNU General Public License v2.0 4 votes vote down vote up
@NotNull
public static InputStream asStream(@NotNull String content) {
  return new CharSequenceInputStream(content, StandardCharsets.UTF_8);
}