import java.io.RandomAccessFile;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Base64;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
this.setTableName(tableName);
// Construct file name
- String fileName = String.format("data/table_%s.csv", tableName);
+ String fileName = String.format("data/table_%s.b64", tableName);
// Debug message
this.getLogger().debug(MessageFormat.format("Trying to open file {0} ...", fileName));
// Debug message
this.getLogger().debug(MessageFormat.format("str({0})={1}", str.length(), str));
+ // Encode line in BASE-64
+ byte[] encoded = Base64.getEncoder().encode(str.trim().getBytes());
+
// The string is now a valid CSV string
- this.getStorageFile().writeBytes(str);
+ this.getStorageFile().write(encoded);
}
/**
// Get next token
String token = tokenizer.nextToken();
+ // If char " is at pos 2 (0,1,2), then cut it of there
+ if ((token.charAt(0) != '"') && (token.charAt(2) == '"')) {
+ // UTF-8 writer characters found
+ token = token.substring(2);
+ }
+
// Debug message
this.getLogger().debug(MessageFormat.format("token={0}", token));
// Verify token, it must have double-quotes on each side
if ((!token.startsWith("\"")) || (!token.endsWith("\""))) {
// Something bad was read
- throw new BadTokenException(MessageFormat.format("Token {0} has not double-quotes on both ends.", token));
+ throw new BadTokenException(MessageFormat.format("Token {0} at position {1} has not double-quotes on both ends.", token, count));
}
// All fine, so remove it
String input = null;
try {
- input = this.getStorageFile().readLine();
+ String base64 = this.getStorageFile().readLine();
+
+ // Decode BASE-64
+ byte[] decoded = Base64.getDecoder().decode(base64);
+
+ // Convert to string
+ input = new String(decoded);
} catch (final IOException ex) {
this.getLogger().catching(ex);
}