use of java.io.InputStreamReader in project camel by apache.
the class AbstractGoogleDriveTestSupport method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
final InputStream in = getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES);
if (in == null) {
throw new IOException(TEST_OPTIONS_PROPERTIES + " could not be found");
}
final StringBuilder builder = new StringBuilder();
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line).append(LINE_SEPARATOR);
}
propertyText = builder.toString();
final Properties properties = new Properties();
try {
properties.load(new StringReader(propertyText));
} catch (IOException e) {
throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
}
//
// // cache test properties
// refreshToken = properties.getProperty(REFRESH_TOKEN_PROPERTY);
// testFolderId = properties.getProperty("testFolderId");
// testFileId = properties.getProperty("testFileId");
// testUserId = properties.getProperty("testUserId");
//
Map<String, Object> options = new HashMap<String, Object>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
options.put(entry.getKey().toString(), entry.getValue());
}
final GoogleDriveConfiguration configuration = new GoogleDriveConfiguration();
IntrospectionSupport.setProperties(configuration, options);
// add GoogleDriveComponent to Camel context
final CamelContext context = super.createCamelContext();
final GoogleDriveComponent component = new GoogleDriveComponent(context);
component.setConfiguration(configuration);
context.addComponent("google-drive", component);
return context;
}
use of java.io.InputStreamReader in project camel by apache.
the class HdfsProducerSplitTest method doTest.
private void doTest(int routeNr) throws Exception {
if (!canTest()) {
return;
}
for (int i = 0; i < 10; ++i) {
template.sendBody("direct:start" + routeNr, "CIAO" + i);
}
stopCamelContext();
FileSystem fs = FileSystem.get(new Configuration());
FileStatus[] status = fs.listStatus(new Path("file:///" + BASE_FILE.toUri() + routeNr));
assertEquals(10, status.length);
for (FileStatus fileStatus : status) {
BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(fileStatus.getPath())));
assertTrue(br.readLine().startsWith("CIAO"));
assertNull(br.readLine());
}
}
use of java.io.InputStreamReader in project camel by apache.
the class HL7MLLPCodecBoundaryTest method testSendHL7Message.
@Test
public void testSendHL7Message() throws Exception {
BufferedReader in = IOHelper.buffered(new InputStreamReader(getClass().getResourceAsStream("/mdm_t02-1022.txt")));
String line = "";
String message = "";
while (line != null) {
if ((line = in.readLine()) != null) {
message += line + "\r";
}
}
message = message.substring(0, message.length() - 1);
assertEquals(1022, message.length());
MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
mockEndpoint.expectedMessageCount(1);
template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", message);
mockEndpoint.assertIsSatisfied();
}
use of java.io.InputStreamReader in project camel by apache.
the class HL7MLLPNettyCodecBoundaryTest method testSendHL7Message.
@Test
public void testSendHL7Message() throws Exception {
BufferedReader in = IOHelper.buffered(new InputStreamReader(getClass().getResourceAsStream("/mdm_t02-1022.txt")));
String line = "";
String message = "";
while (line != null) {
if ((line = in.readLine()) != null) {
message += line + "\r";
}
}
message = message.substring(0, message.length() - 1);
assertEquals(1022, message.length());
MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
mockEndpoint.expectedMessageCount(1);
template.requestBody("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder", message);
mockEndpoint.assertIsSatisfied();
}
use of java.io.InputStreamReader in project camel by apache.
the class FallbackTypeConverter method unmarshal.
protected Object unmarshal(Unmarshaller unmarshaller, Exchange exchange, Object value) throws JAXBException, UnsupportedEncodingException, XMLStreamException {
try {
XMLStreamReader xmlReader;
if (value instanceof XMLStreamReader) {
xmlReader = (XMLStreamReader) value;
} else if (value instanceof InputStream) {
if (needFiltering(exchange)) {
xmlReader = staxConverter.createXMLStreamReader(new NonXmlFilterReader(new InputStreamReader((InputStream) value, IOHelper.getCharsetName(exchange))));
} else {
xmlReader = staxConverter.createXMLStreamReader((InputStream) value, exchange);
}
} else if (value instanceof Reader) {
Reader reader = (Reader) value;
if (needFiltering(exchange)) {
if (!(value instanceof NonXmlFilterReader)) {
reader = new NonXmlFilterReader((Reader) value);
}
}
xmlReader = staxConverter.createXMLStreamReader(reader);
} else if (value instanceof Source) {
xmlReader = staxConverter.createXMLStreamReader((Source) value);
} else {
throw new IllegalArgumentException("Cannot convert from " + value.getClass());
}
return unmarshaller.unmarshal(xmlReader);
} finally {
if (value instanceof Closeable) {
IOHelper.close((Closeable) value, "Unmarshalling", LOG);
}
}
}
Aggregations