/** * Writes string-to-string map to given data output. * * @param out Data output. * @param map Map. * @throws IOException If write failed. */ public static void writeStringMap(DataOutput out, @Nullable Map<String, String> map) throws IOException { if (map != null) { out.writeInt(map.size()); for (Map.Entry<String, String> e : map.entrySet()) { writeUTF(out, e.getKey()); writeUTF(out, e.getValue()); } } else out.writeInt(-1); }
/** * 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); }
/** * Writes string-to-string map to given data output. * * @param out Data output. * @param map Map. * @throws IOException If write failed. */ public static void writeStringMap(DataOutput out, @Nullable Map<String, String> map) throws IOException { if (map != null) { out.writeInt(map.size()); for (Map.Entry<String, String> e : map.entrySet()) { writeUTF(out, e.getKey()); writeUTF(out, e.getValue()); } } else out.writeInt(-1); }