Java 类org.apache.commons.io.input.CharSequenceInputStream 实例源码

项目:smartsheet-java-sdk    文件:StreamUtilTest.java   
@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());
}
项目:vespa    文件:DomSearchCoverageBuilderTest.java   
private static SearchCoverage newSearchCoverage(String xml) throws Exception {
    return DomSearchCoverageBuilder.build(
            new ModelElement(DocumentBuilderFactory.newInstance()
                                                   .newDocumentBuilder()
                                                   .parse(new CharSequenceInputStream(xml, StandardCharsets.UTF_8))
                                                   .getDocumentElement()));
}
项目:vespa    文件:DomContentSearchBuilderTest.java   
private static ContentSearch newContentSearch(String xml) throws Exception {
    return DomContentSearchBuilder.build(
            new ModelElement(DocumentBuilderFactory.newInstance()
                                                   .newDocumentBuilder()
                                                   .parse(new CharSequenceInputStream(xml, StandardCharsets.UTF_8))
                                                   .getDocumentElement()));
}
项目:vespa    文件:DomTuningDispatchBuilderTest.java   
private static TuningDispatch newTuningDispatch(String xml) throws Exception {
    return DomTuningDispatchBuilder.build(
            new ModelElement(DocumentBuilderFactory.newInstance()
                                                   .newDocumentBuilder()
                                                   .parse(new CharSequenceInputStream(xml, StandardCharsets.UTF_8))
                                                   .getDocumentElement()));
}
项目:edemocracia    文件:ParticipacaoResource.java   
/**
 * @see javax.faces.application.Resource#getInputStream()
 */
@Override
public InputStream getInputStream() throws IOException {

    String csv = CSVParticipacaoExporter.export(listaDadosComunidade);
    return new CharSequenceInputStream(csv, "ISO-8859-1");
}
项目:verify-hub    文件:TestResponse.java   
public TestResponse(int status, String entity) {
    this.status = status;
    this.inputStream = new CharSequenceInputStream(entity, "UTF-8");
}
项目:pac4j-extensions    文件:DatabaseLoadedSAML2ClientConfiguration.java   
/**
 * Initializes the IdP resource.
 */
private void initializeIdentityProviderMetadata() {
    final InputStream is = new CharSequenceInputStream(identityProviderMetadata, "UTF-8");
    this.identityProviderMetadataResourceFromDatabase = new InputStreamResource(is);
}
项目:oxTrust    文件:TrustRelationshipWebService.java   
private boolean saveSpMetaDataFileSourceTypeFile(GluuSAMLTrustRelationship  trustRelationship, String inum, String metadata) throws IOException {
    logger.trace("Saving metadata file source type: File");
    String spMetadataFileName = trustRelationship.getSpMetaDataFN();
    boolean emptySpMetadataFileName = StringHelper.isEmpty(spMetadataFileName);

    if (StringHelper.isEmpty(metadata)) {
        if (emptySpMetadataFileName) {
            return false;
        }

        // Admin doesn't provide new file. Check if we already has this file
        String filePath = shibboleth3ConfService.getSpMetadataFilePath(spMetadataFileName);
        if (filePath == null) {
            return false;
        }

        File file = new File(filePath);
        if (!file.exists()) {
            return false;
        }

        // File already exist
        return true;
    }

    if (emptySpMetadataFileName) {
        // Generate new file name
        spMetadataFileName = shibboleth3ConfService.getSpNewMetadataFileName(trustRelationship);
        trustRelationship.setSpMetaDataFN(spMetadataFileName);
        if (trustRelationship.getDn() == null) {
            String dn = trustService.getDnForTrustRelationShip(inum);
            trustRelationship.setDn(dn);
            trustService.addTrustRelationship(trustRelationship);
        } else {
            trustService.updateTrustRelationship(trustRelationship);
        }
    }
    String result = shibboleth3ConfService.saveSpMetadataFile(spMetadataFileName, new CharSequenceInputStream(metadata, StandardCharsets.UTF_8));
    if (StringHelper.isNotEmpty(result)) {
        metadataValidationTimer.queue(result);
    } else {
        //facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to save SP meta-data file. Please check if you provide correct file");
    }

    return StringHelper.isNotEmpty(result);

}