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