You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/02/25 10:23:13 UTC
[4/4] camel git commit: CAMEL-8356 Polish the code of
IOConverterCharsetTest
CAMEL-8356 Polish the code of IOConverterCharsetTest
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c02c61df
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c02c61df
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c02c61df
Branch: refs/heads/camel-2.14.x
Commit: c02c61df6feb74d892c984023abe2c864f9ab4f2
Parents: f07a0c0
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Feb 25 14:29:20 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Feb 25 17:22:13 2015 +0800
----------------------------------------------------------------------
.../camel/converter/IOConverterCharsetTest.java | 90 +++++++++++---------
1 file changed, 51 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c02c61df/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
index 5d0193f..4d30291 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
@@ -32,67 +32,79 @@ public class IOConverterCharsetTest extends ContextTestSupport {
File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
InputStream in = IOConverter.toInputStream(file, "UTF-8");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
- "UTF-8"));
- String line = reader.readLine();
- String naiveLine = naiveReader.readLine();
- assertEquals(naiveLine, line);
- assertEquals(CONTENT, line);
- reader.close();
- naiveReader.close();
+ BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+ try {
+ String line = reader.readLine();
+ String naiveLine = naiveReader.readLine();
+ assertEquals(naiveLine, line);
+ assertEquals(CONTENT, line);
+ } finally {
+ reader.close();
+ naiveReader.close();
+ }
+
}
public void testToInputStreamFileWithCharsetLatin1() throws Exception {
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
- "ISO-8859-1"));
- String line = reader.readLine();
- String naiveLine = naiveReader.readLine();
- assertEquals(naiveLine, line);
- assertEquals(CONTENT, line);
- reader.close();
- naiveReader.close();
+ 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();
+ }
}
public void testToInputStreamFileDirectByteDumpWithCharsetLatin1() throws Exception {
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
InputStream naiveIn = new FileInputStream(file);
- byte[] bytes = new byte[8192];
- in.read(bytes);
- byte[] naiveBytes = new byte[8192];
- naiveIn.read(naiveBytes);
- assertFalse("both input streams deliver the same byte sequence", Arrays.equals(naiveBytes, bytes));
- in.close();
- naiveIn.close();
+ try {
+ byte[] bytes = new byte[8192];
+ in.read(bytes);
+ byte[] naiveBytes = new byte[8192];
+ naiveIn.read(naiveBytes);
+ assertFalse("both input streams deliver the same byte sequence", Arrays.equals(naiveBytes, bytes));
+ } finally {
+ in.close();
+ naiveIn.close();
+ }
}
public void testToReaderFileWithCharsetUTF8() throws Exception {
File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
BufferedReader reader = IOConverter.toReader(file, "UTF-8");
- BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
- "UTF-8"));
- String line = reader.readLine();
- String naiveLine = naiveReader.readLine();
- assertEquals(naiveLine, line);
- assertEquals(CONTENT, line);
- reader.close();
- naiveReader.close();
+ BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+ try {
+ String line = reader.readLine();
+ String naiveLine = naiveReader.readLine();
+ assertEquals(naiveLine, line);
+ assertEquals(CONTENT, line);
+ } finally {
+ reader.close();
+ naiveReader.close();
+ }
}
public void testToReaderFileWithCharsetLatin1() throws Exception {
File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
BufferedReader reader = IOConverter.toReader(file, "ISO-8859-1");
- BufferedReader naiveReader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
- "ISO-8859-1"));
- String line = reader.readLine();
- String naiveLine = naiveReader.readLine();
- assertEquals(naiveLine, line);
- assertEquals(CONTENT, line);
- reader.close();
- naiveReader.close();
+ 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();
+ }
}
}