Search in sources :

Example 11 with BufferedReader

use of java.io.BufferedReader in project camel by apache.

the class IOConverterCharsetTest method testToInputStreamFileWithCharsetLatin1.

public void testToInputStreamFileWithCharsetLatin1() throws Exception {
    switchToDefaultCharset("UTF-8");
    File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
    InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
    // do read with default charset!
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1"));
    try {
        String line = reader.readLine();
        String naiveLine = naiveReader.readLine();
        assertEquals(naiveLine, line);
        assertEquals(CONTENT, line);
    } finally {
        reader.close();
        naiveReader.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 12 with BufferedReader

use of java.io.BufferedReader 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 13 with BufferedReader

use of java.io.BufferedReader 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 14 with BufferedReader

use of java.io.BufferedReader 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 15 with BufferedReader

use of java.io.BufferedReader 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)

Aggregations

BufferedReader (java.io.BufferedReader)4790 InputStreamReader (java.io.InputStreamReader)2944 IOException (java.io.IOException)2260 FileReader (java.io.FileReader)1112 File (java.io.File)818 InputStream (java.io.InputStream)730 ArrayList (java.util.ArrayList)676 FileInputStream (java.io.FileInputStream)626 URL (java.net.URL)390 Test (org.junit.Test)367 FileNotFoundException (java.io.FileNotFoundException)329 StringReader (java.io.StringReader)282 BufferedWriter (java.io.BufferedWriter)205 HashMap (java.util.HashMap)199 Matcher (java.util.regex.Matcher)196 OutputStreamWriter (java.io.OutputStreamWriter)190 HttpURLConnection (java.net.HttpURLConnection)190 PrintWriter (java.io.PrintWriter)187 Reader (java.io.Reader)169 Socket (java.net.Socket)151