/** * Reads string-to-string map written by {@link #writeStringMap(DataOutput, Map)}. * * @param in Data input. * @throws IOException If write failed. * @return Read result. */ public static Map<String, String> readStringMap(DataInput in) throws IOException { int size = in.readInt(); if (size == -1) return null; else { Map<String, String> map = U.newHashMap(size); for (int i = 0; i < size; i++) map.put(readUTF(in), readUTF(in)); return map; } }
/** * Writes the given String to a DataOutput, reads from DataInput, then checks if they are the same. * * @param s0 The String to check serialization for. * @throws Exception On error. */ private static void checkString(String s0) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutput dout = new DataOutputStream(baos); IgfsUtils.writeUTF(dout, s0); DataInput din = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); String s1 = IgfsUtils.readUTF(din); assertEquals(s0, s1); }
/** * Reads string-to-string map written by {@link #writeStringMap(DataOutput, Map)}. * * @param in Data input. * @throws IOException If write failed. * @return Read result. */ public static Map<String, String> readStringMap(DataInput in) throws IOException { int size = in.readInt(); if (size == -1) return null; else { Map<String, String> map = U.newHashMap(size); for (int i = 0; i < size; i++) map.put(readUTF(in), readUTF(in)); return map; } }