SerializationUtil { public void writeFile(String file, List<ByteString> input) { BufferedOutputStream bos = null; try { bos = new BufferedOutputStream(new FileOutputStream(file)); for (ByteString data : input) { bos.write(data.toByteArray()); } } catch (IOException e) { e.printStackTrace(); } finally { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } }  List<ByteString> readfile(String file, long from, int size, int N); void writeFile(String file, List<ByteString> input);  }
@Test public void testWriteFile() { list = instance.readfile("src/util/dump.jpg", 0, 1024 * 1024, 1); list.addAll(instance.readfile("src/util/dump.jpg", 1, 1024 * 1024, 1)); list.addAll(instance.readfile("src/util/dump.jpg", 2, 1024 * 1024, -1)); System.out.println(list.size()); for (ByteString data : list) { } instance.writeFile("src/util/dump2.jpg", list); File file = new File("src/util/dump2.jpg"); assertTrue(file.exists()); assertTrue(file.isFile()); assertEquals(8388608, file.length()); }