@Test public void testPopulate() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Map<byte[], byte[]> inMap = new HashMap<byte[], byte[]>(); Map<String,Object> actualMap = new HashMap<String,Object>(), expectedMap = new HashMap<String,Object>(); Map<String, StreamProxy> actualStreams = new HashMap<String, StreamProxy>(), expectedStreams = new HashMap<String, StreamProxy>(); Date ts = new Date(); expectedMap.put("num", 17L); expectedMap.put("whatevs", "a string"); expectedMap.put("exfiltrated", ts.clone()); expectedStreams.put("Content", new FileProxy("some/bullshit/file.dat")); expectedStreams.put("Slack", new BufferProxy(new byte[] {0x02, 0x03, 0x05, 0x08, 0x13, 0x21})); inMap.put(createColSpec(17L, "num"), Bytes.toBytes(17L)); inMap.put(createColSpec("a string", "whatevs"), Bytes.toBytes("a string")); inMap.put(createColSpec(ts, "exfiltrated"), Bytes.toBytes(ts.getTime())); inMap.put(createColSpec(new FileProxy(""), "Content"), Bytes.toBytes("some/bullshit/file.dat")); inMap.put(createColSpec(new BufferProxy(null), "Slack"), new byte[] {0x02, 0x03, 0x05, 0x08, 0x13, 0x21}); populate(inMap, actualMap, actualStreams); assertEquals(expectedMap, actualMap); assertEquals(expectedStreams.size(), actualStreams.size()); assertTrue(actualStreams.containsKey("Content")); assertTrue(actualStreams.containsKey("Slack")); assertEquals("some/bullshit/file.dat", ((FileProxy)actualStreams.get("Content")).getPath()); InputStream str = actualStreams.get("Slack").open(new RawLocalFileSystem()); byte[] tempBuf = new byte[6]; assertEquals(6, str.read(tempBuf)); assertEquals(0, str.available()); assertArrayEquals(new byte[] {0x02, 0x03, 0x05, 0x08, 0x13, 0x21}, tempBuf); }
public static void populate(Map<byte[], byte[]> input, Map<String,Object> out, Map<String, StreamProxy> streams) { out.clear(); streams.clear(); Set<Map.Entry<byte[], byte[]>> set = input.entrySet(); byte[] key = null; for (Map.Entry<byte[], byte[]> pair: set) { key = pair.getKey(); switch (key[0]) { case LONG: case STRING: case DATE: case JSON: case BYTE_ARRAY: out.put(colName(key), unmarshall(key, pair.getValue())); break; case BUFFER_STREAM: case FILE_STREAM: streams.put(colName(key), (StreamProxy)unmarshall(key, pair.getValue())); break; } } }
FsEntryHBaseCommon { public static void populate(Map<byte[], byte[]> input, Map<String,Object> out, Map<String, StreamProxy> streams) { out.clear(); streams.clear(); Set<Map.Entry<byte[], byte[]>> set = input.entrySet(); byte[] key = null; for (Map.Entry<byte[], byte[]> pair: set) { key = pair.getKey(); switch (key[0]) { case LONG: case STRING: case DATE: case JSON: case BYTE_ARRAY: out.put(colName(key), unmarshall(key, pair.getValue())); break; case BUFFER_STREAM: case FILE_STREAM: streams.put(colName(key), (StreamProxy)unmarshall(key, pair.getValue())); break; } } } }
FsEntryHBaseCommon { public static void populate(Map<byte[], byte[]> input, Map<String,Object> out, Map<String, StreamProxy> streams) { out.clear(); streams.clear(); Set<Map.Entry<byte[], byte[]>> set = input.entrySet(); byte[] key = null; for (Map.Entry<byte[], byte[]> pair: set) { key = pair.getKey(); switch (key[0]) { case LONG: case STRING: case DATE: case JSON: case BYTE_ARRAY: out.put(colName(key), unmarshall(key, pair.getValue())); break; case BUFFER_STREAM: case FILE_STREAM: streams.put(colName(key), (StreamProxy)unmarshall(key, pair.getValue())); break; } } }  }
FsEntryHBaseCommon { public static void populate(Map<byte[], byte[]> input, Map<String,Object> out, Map<String, StreamProxy> streams) { out.clear(); streams.clear(); Set<Map.Entry<byte[], byte[]>> set = input.entrySet(); byte[] key = null; for (Map.Entry<byte[], byte[]> pair: set) { key = pair.getKey(); switch (key[0]) { case LONG: case STRING: case DATE: case JSON: case BYTE_ARRAY: out.put(colName(key), unmarshall(key, pair.getValue())); break; case BUFFER_STREAM: case FILE_STREAM: streams.put(colName(key), (StreamProxy)unmarshall(key, pair.getValue())); break; } } }  static byte typeVal(Object o); static byte[] createColSpec(Object o, String colName); static byte[] createColSpec(byte type, String colName); static String colName(byte[] colSpec); @SuppressWarnings("fallthrough") static Object unmarshall(byte[] colSpec, byte[] colVal); static void populate(Map<byte[], byte[]> input, Map<String,Object> out, Map<String, StreamProxy> streams); }
FsEntryHBaseCommon { public static void populate(Map<byte[], byte[]> input, Map<String,Object> out, Map<String, StreamProxy> streams) { out.clear(); streams.clear(); Set<Map.Entry<byte[], byte[]>> set = input.entrySet(); byte[] key = null; for (Map.Entry<byte[], byte[]> pair: set) { key = pair.getKey(); switch (key[0]) { case LONG: case STRING: case DATE: case JSON: case BYTE_ARRAY: out.put(colName(key), unmarshall(key, pair.getValue())); break; case BUFFER_STREAM: case FILE_STREAM: streams.put(colName(key), (StreamProxy)unmarshall(key, pair.getValue())); break; } } }  static byte typeVal(Object o); static byte[] createColSpec(Object o, String colName); static byte[] createColSpec(byte type, String colName); static String colName(byte[] colSpec); @SuppressWarnings("fallthrough") static Object unmarshall(byte[] colSpec, byte[] colVal); static void populate(Map<byte[], byte[]> input, Map<String,Object> out, Map<String, StreamProxy> streams); static final byte LONG; static final byte STRING; static final byte DATE; static final byte JSON; static final byte BYTE_ARRAY; static final byte BUFFER_STREAM; static final byte FILE_STREAM; }