Search in sources :

Example 16 with InputStreamReader

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with InputStreamReader

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());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) Configuration(org.apache.hadoop.conf.Configuration) InputStreamReader(java.io.InputStreamReader) FileSystem(org.apache.hadoop.fs.FileSystem) BufferedReader(java.io.BufferedReader)

Example 18 with InputStreamReader

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) BufferedReader(java.io.BufferedReader) Test(org.junit.Test)

Example 19 with InputStreamReader

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();
}
Also used : InputStreamReader(java.io.InputStreamReader) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) BufferedReader(java.io.BufferedReader) Test(org.junit.Test)

Example 20 with InputStreamReader

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);
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Closeable(java.io.Closeable) XMLStreamReader(javax.xml.stream.XMLStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) Source(javax.xml.transform.Source)

Aggregations

InputStreamReader (java.io.InputStreamReader)4181 BufferedReader (java.io.BufferedReader)2938 IOException (java.io.IOException)1843 InputStream (java.io.InputStream)1083 FileInputStream (java.io.FileInputStream)767 ArrayList (java.util.ArrayList)494 URL (java.net.URL)471 File (java.io.File)448 Reader (java.io.Reader)446 Test (org.junit.Test)336 HttpURLConnection (java.net.HttpURLConnection)253 ByteArrayInputStream (java.io.ByteArrayInputStream)231 OutputStreamWriter (java.io.OutputStreamWriter)218 FileNotFoundException (java.io.FileNotFoundException)210 HashMap (java.util.HashMap)171 Socket (java.net.Socket)170 OutputStream (java.io.OutputStream)150 URLConnection (java.net.URLConnection)148 StringWriter (java.io.StringWriter)135 Path (org.apache.hadoop.fs.Path)123