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
This commit is contained in:
David Huynh 2011-09-29 14:02:12 +00:00
parent b6b8da99a8
commit d047acf1d1

View File

@ -7,7 +7,6 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.CharBuffer;
import com.google.refine.importing.FormatGuesser; 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); Reader reader = encoding != null ? new InputStreamReader(is, encoding) : new InputStreamReader(is);
int totalBytes = 0; int totalBytes = 0;
int bytes;
int openBraces = 0; int openBraces = 0;
int closeBraces = 0; int closeBraces = 0;
int openAngleBrackets = 0; int openAngleBrackets = 0;
int closeAngleBrackets = 0; int closeAngleBrackets = 0;
CharBuffer charBuffer = CharBuffer.allocate(4096); char[] chars = new char[4096];
while (totalBytes < 64 * 1024 && (bytes = reader.read(charBuffer)) > 0) { int c;
String chunk = charBuffer.toString(); while (totalBytes < 64 * 1024 && (c = reader.read(chars)) > 0) {
String chunk = String.valueOf(chars, 0, c);
openBraces += countSubstrings(chunk, "{"); openBraces += countSubstrings(chunk, "{");
closeBraces += countSubstrings(chunk, "}"); closeBraces += countSubstrings(chunk, "}");
openAngleBrackets += countSubstrings(chunk, "<"); openAngleBrackets += countSubstrings(chunk, "<");
closeAngleBrackets += countSubstrings(chunk, ">"); closeAngleBrackets += countSubstrings(chunk, ">");
charBuffer.clear(); totalBytes += c;
totalBytes += bytes;
} }
if (openBraces >= 5 && closeBraces >= 5) { if (openBraces >= 5 && closeBraces >= 5) {