SerializationUtil { public List<ByteString> readfile(String file, long from, int size, int N) { List<ByteString> output = new LinkedList<>(); BufferedInputStream bis = null; try { byte[] data = new byte[size]; bis = new BufferedInputStream(new FileInputStream(file)); bis.skip(from * size); int index = 0; while (bis.read(data) > 0 && (N == -1 || index++ < N)) { output.add(ByteString.copyFrom(data)); } } catch (IOException e) { e.printStackTrace(); } finally { if (bis != null) { try { bis.close(); } catch (IOException e) { e.printStackTrace(); } } } return output; }  List<ByteString> readfile(String file, long from, int size, int N); void writeFile(String file, List<ByteString> input);  }
@Test public void testReadfile() { list = instance.readfile("src/util/dump.jpg", 0, 1024, -1); assertEquals(list.size(), 7601); assertEquals(list.get(0).size(), 1024); }