From d047acf1d1ac71ffcdda8ad7871ee0b8df6cfd91 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Thu, 29 Sep 2011 14:02:12 +0000 Subject: [PATCH] Fixed Issue 452: Importing using Clipboard function does not guess structure correctly for XML or JSON git-svn-id: http://google-refine.googlecode.com/svn/trunk@2263 7d457c2a-affb-35e4-300a-418c747d4874 --- .../google/refine/importers/TextFormatGuesser.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/main/src/com/google/refine/importers/TextFormatGuesser.java b/main/src/com/google/refine/importers/TextFormatGuesser.java index 9c1768a59..cddf04c6a 100644 --- a/main/src/com/google/refine/importers/TextFormatGuesser.java +++ b/main/src/com/google/refine/importers/TextFormatGuesser.java @@ -7,7 +7,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; -import java.nio.CharBuffer; import com.google.refine.importing.FormatGuesser; @@ -21,22 +20,21 @@ public class TextFormatGuesser implements FormatGuesser { Reader reader = encoding != null ? new InputStreamReader(is, encoding) : new InputStreamReader(is); int totalBytes = 0; - int bytes; int openBraces = 0; int closeBraces = 0; int openAngleBrackets = 0; int closeAngleBrackets = 0; - CharBuffer charBuffer = CharBuffer.allocate(4096); - while (totalBytes < 64 * 1024 && (bytes = reader.read(charBuffer)) > 0) { - String chunk = charBuffer.toString(); + char[] chars = new char[4096]; + int c; + while (totalBytes < 64 * 1024 && (c = reader.read(chars)) > 0) { + String chunk = String.valueOf(chars, 0, c); openBraces += countSubstrings(chunk, "{"); closeBraces += countSubstrings(chunk, "}"); openAngleBrackets += countSubstrings(chunk, "<"); closeAngleBrackets += countSubstrings(chunk, ">"); - charBuffer.clear(); - totalBytes += bytes; + totalBytes += c; } if (openBraces >= 5 && closeBraces >= 5) {