private List<Map.Entry<String, String>> readListFromFile(File file) throws IOException { InputStream is = new FileInputStream(file); String str; try { str = IOHelper.readInputStreamToString(is, charset); } finally { is.close(); } String[] list = str.split("\0", -1); List<Map.Entry<String, String>> all = new ArrayList<Map.Entry<String, String>>(); for (int i = 0; i + 1 < list.length; i += 2) { all.add(new SimpleEntry<String, String>(list[i], list[i + 1])); } return all; }
private File writeIterableToTempFile(Iterable<Map.Entry<String, String>> it) throws IOException { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> me : it) { if (me.getKey().contains("\0")) { throw new RuntimeException("Key cannot contain the null character: " + me.getKey()); } if (me.getValue().contains("\0")) { throw new RuntimeException( "Value for key '" + me.getKey() + "' cannot contain the null " + "character: " + me.getKey()); } sb.append(me.getKey()).append('\0'); sb.append(me.getValue()).append('\0'); } return IOHelper.writeToTempFile(sb.toString(), charset); }