Search in sources :

Example 21 with ReaderInputStream

use of org.apache.commons.io.input.ReaderInputStream in project tutorials by eugenp.

the class JavaXToInputStreamUnitTest method givenUsingGuava_whenConvertingStringToInputStream_thenCorrect.

@Test
public final void givenUsingGuava_whenConvertingStringToInputStream_thenCorrect() throws IOException {
    final String initialString = "text";
    final InputStream targetStream = new ReaderInputStream(CharSource.wrap(initialString).openStream());
    IOUtils.closeQuietly(targetStream);
}
Also used : ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) FileInputStream(java.io.FileInputStream) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 22 with ReaderInputStream

use of org.apache.commons.io.input.ReaderInputStream in project maven-plugins by apache.

the class ReaderFormatter method getFileSetTransformers.

@Nullable
public static InputStreamTransformer getFileSetTransformers(final AssemblerConfigurationSource configSource, final boolean isFiltered, String fileSetLineEnding) throws AssemblyFormattingException {
    final LineEndings lineEndingToUse = LineEndingsUtils.getLineEnding(fileSetLineEnding);
    final boolean transformLineEndings = !LineEndings.keep.equals(lineEndingToUse);
    if (transformLineEndings || isFiltered) {
        return new InputStreamTransformer() {

            @Override
            @Nonnull
            public InputStream transform(@Nonnull PlexusIoResource plexusIoResource, @Nonnull InputStream inputStream) throws IOException {
                InputStream result = inputStream;
                if (isFiltered) {
                    boolean isPropertyFile = AssemblyFileUtils.isPropertyFile(plexusIoResource.getName());
                    final String encoding = isPropertyFile ? "ISO-8859-1" : configSource.getEncoding();
                    Reader source = encoding != null ? new InputStreamReader(inputStream, encoding) : // wtf platform encoding ? TODO: Fix this
                    new InputStreamReader(inputStream);
                    Reader filtered = createReaderFilter(source, configSource.getEscapeString(), configSource.getDelimiters(), configSource, isPropertyFile);
                    result = encoding != null ? new ReaderInputStream(filtered, encoding) : new ReaderInputStream(filtered);
                }
                if (transformLineEndings) {
                    checkifFileTypeIsAppropriateForLineEndingTransformation(plexusIoResource);
                    result = LineEndingsUtils.lineEndingConverter(result, lineEndingToUse);
                }
                return result;
            }
        };
    }
    return null;
}
Also used : LineEndings(org.apache.maven.plugins.assembly.utils.LineEndings) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) PlexusIoResource(org.codehaus.plexus.components.io.resources.PlexusIoResource) InputStreamReader(java.io.InputStreamReader) Nonnull(javax.annotation.Nonnull) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) InputStream(java.io.InputStream) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Nullable(javax.annotation.Nullable)

Example 23 with ReaderInputStream

use of org.apache.commons.io.input.ReaderInputStream in project samza by apache.

the class TestApplicationMasterRestClient method setupMockClientResponse.

private void setupMockClientResponse(int statusCode, String statusReason, String responseBody) throws IOException {
    StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(statusCode);
    when(statusLine.getReasonPhrase()).thenReturn(statusReason);
    HttpEntity entity = mock(HttpEntity.class);
    when(entity.getContent()).thenReturn(new ReaderInputStream(new StringReader(responseBody)));
    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    when(response.getStatusLine()).thenReturn(statusLine);
    when(response.getEntity()).thenReturn(entity);
    when(mockClient.execute(any(HttpHost.class), any(HttpGet.class))).thenReturn(response);
}
Also used : StatusLine(org.apache.http.StatusLine) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) HttpEntity(org.apache.http.HttpEntity) HttpHost(org.apache.http.HttpHost) HttpGet(org.apache.http.client.methods.HttpGet) StringReader(java.io.StringReader) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 24 with ReaderInputStream

use of org.apache.commons.io.input.ReaderInputStream in project iaf by ibissource.

the class TestBlobs method testWriteAndReadClobUsingDbmsSupport.

public void testWriteAndReadClobUsingDbmsSupport(int numOfBlocks, int blockSize) throws Exception {
    String block = getBigString(1, blockSize);
    String insertQuery = "INSERT INTO TEMP (TKEY,TCLOB) VALUES (20,?)";
    String selectQuery = "SELECT TCLOB FROM TEMP WHERE TKEY=20";
    try (PreparedStatement stmt = connection.prepareStatement(insertQuery)) {
        Object clobInsertHandle = dbmsSupport.getClobHandle(stmt, 1);
        try (Writer clobWriter = dbmsSupport.getClobWriter(stmt, 1, clobInsertHandle)) {
            for (int i = 0; i < numOfBlocks; i++) {
                clobWriter.append(block);
            }
        }
        dbmsSupport.applyClobParameter(stmt, 1, clobInsertHandle);
        stmt.execute();
    }
    try (PreparedStatement stmt = executeTranslatedQuery(connection, selectQuery, QueryType.SELECT)) {
        try (ResultSet resultSet = stmt.executeQuery()) {
            resultSet.next();
            try (Reader clobReader = dbmsSupport.getClobReader(resultSet, 1)) {
                int length = readStream(new ReaderInputStream(clobReader));
                assertEquals(blockSize * numOfBlocks, length);
            }
        }
    }
}
Also used : ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) ResultSet(java.sql.ResultSet) Reader(java.io.Reader) PreparedStatement(java.sql.PreparedStatement) Writer(java.io.Writer)

Example 25 with ReaderInputStream

use of org.apache.commons.io.input.ReaderInputStream in project pentaho-platform by pentaho.

the class ClientUtilsTest method testgetResultDom4jDocumentException3.

@Test(expected = ServiceException.class)
public void testgetResultDom4jDocumentException3() throws Exception {
    HttpResponse httpResponseMock = mock(HttpResponse.class);
    HttpEntity httpEntityMock = mock(HttpEntity.class);
    StatusLine statusLineMock = mock(StatusLine.class);
    HttpClient httpClientMock = mock(HttpClient.class);
    HttpGet method = mock(HttpGet.class);
    when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
    when(httpClientMock.execute(any(HttpUriRequest.class))).thenReturn(httpResponseMock);
    when(statusLineMock.getStatusCode()).thenReturn(OK_CODE);
    InputStream inputStream = new ReaderInputStream(new StringReader(XML_BROKEN));
    when(httpResponseMock.getEntity()).thenReturn(httpEntityMock);
    when(httpEntityMock.getContent()).thenReturn(inputStream);
    Document document;
    document = ClientUtil.getResultDom4jDocument(httpClientMock, method);
    assertNull(document);
}
Also used : StatusLine(org.apache.http.StatusLine) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) HttpEntity(org.apache.http.HttpEntity) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) InputStream(java.io.InputStream) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) StringReader(java.io.StringReader) HttpResponse(org.apache.http.HttpResponse) Document(org.dom4j.Document) Test(org.junit.Test)

Aggregations

ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)25 StringReader (java.io.StringReader)16 Test (org.junit.Test)15 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)8 User (org.eclipse.sw360.datahandler.thrift.users.User)8 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)4 InputStreamReader (java.io.InputStreamReader)4 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 HttpEntity (org.apache.http.HttpEntity)3 StatusLine (org.apache.http.StatusLine)3 HttpGet (org.apache.http.client.methods.HttpGet)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)3 TestHelper.assertLicenseInfoParsingResult (org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult)3 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)2 WebApplicationConfiguration (com.evolveum.midpoint.web.security.WebApplicationConfiguration)2