camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [3/4] camel git commit: CAMEL-8356 Clean up the code
Date Wed, 25 Feb 2015 09:23:12 GMT
CAMEL-8356 Clean up the code


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f07a0c02
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f07a0c02
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f07a0c02

Branch: refs/heads/camel-2.14.x
Commit: f07a0c0291c92567bb26ad1088d90a917060b692
Parents: 4be0f5b
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Feb 25 12:57:37 2015 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Feb 25 17:22:01 2015 +0800

----------------------------------------------------------------------
 .../org/apache/camel/converter/IOConverter.java |  34 ++---
 .../camel/converter/IOConverterCharsetTest.java | 143 +++++++++++--------
 2 files changed, 99 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f07a0c02/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
index 3ec51c6..cf33390 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
@@ -79,31 +79,31 @@ public final class IOConverter {
 
     public static InputStream toInputStream(File file, String charset) throws IOException
{
         if (charset != null) {
-        	final BufferedReader reader = toReader(file, charset);
-        	final Charset defaultStreamCharset = Charset.forName("UTF-8");
+            final BufferedReader reader = toReader(file, charset);
+            final Charset defaultStreamCharset = Charset.forName("UTF-8");
             return new InputStream() {
-            	private ByteBuffer bufferBytes;
-            	private CharBuffer bufferedChars = CharBuffer.allocate(4096);
-            	
+                private ByteBuffer bufferBytes;
+                private CharBuffer bufferedChars = CharBuffer.allocate(4096);
+
                 @Override
                 public int read() throws IOException {
-                	if (bufferBytes == null || bufferBytes.remaining() <= 0) {
-                		bufferedChars.clear();
-                		int len = reader.read(bufferedChars);
-                		bufferedChars.flip();
-                		if (len == -1) {
-                			return -1;
-                		}
-                		bufferBytes = defaultStreamCharset.encode(bufferedChars);
-                	}
-					return bufferBytes.get();
+                    if (bufferBytes == null || bufferBytes.remaining() <= 0) {
+                        bufferedChars.clear();
+                        int len = reader.read(bufferedChars);
+                        bufferedChars.flip();
+                        if (len == -1) {
+                            return -1;
+                        }
+                        bufferBytes = defaultStreamCharset.encode(bufferedChars);
+                    }
+                    return bufferBytes.get();
                 }
-                
+
                 @Override
                 public void close() throws IOException {
                     reader.close();
                 }
-                
+
                 @Override
                 public void reset() throws IOException {
                     reader.reset();

http://git-wip-us.apache.org/repos/asf/camel/blob/f07a0c02/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 672e84a..5d0193f 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
@@ -1,3 +1,19 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.camel.converter;
 
 import java.io.BufferedReader;
@@ -10,68 +26,73 @@ import java.util.Arrays;
 import org.apache.camel.ContextTestSupport;
 
 public class IOConverterCharsetTest extends ContextTestSupport {
+    private static final String CONTENT = "G\u00f6tzend\u00e4mmerung,Joseph und seine Br\u00fcder";
 
-	public void testToInputStreamFileWithCharsetUTF8() throws Exception {
-		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("Götzendämmerung,Joseph und seine Brüder", line);
-		reader.close();
-		naiveReader.close();
-	}
+    public void testToInputStreamFileWithCharsetUTF8() throws Exception {
+        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();
+    }
 
-	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("Götzendämmerung,Joseph und seine Brüder", line);
-		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();
-	}
-	
-	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("Götzendämmerung,Joseph und seine Brüder", line);
-		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();
+    }
+
+    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();
+    }
+
+    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();
+    }
+
+    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();
+    }
 
-	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("Götzendämmerung,Joseph und seine Brüder", line);
-		reader.close();
-		naiveReader.close();
-	}
-	
 }


Mime
View raw message