private synchronized void loadFileData() throws IOException { if (data != null) { return; } InputStream in = null; try { in = dataSource.open(); ByteArrayOutputStream out = new ByteArrayOutputStream(); addLineOffset(0); // Line 0 starts at offset 0 LineNumberMapBuilder mapBuilder = new LineNumberMapBuilder(this); // Copy all of the data from the file into the byte array output // stream byte[] buf = new byte[1024]; int n; while ((n = in.read(buf)) >= 0) { mapBuilder.addData(buf, n); out.write(buf, 0, n); } mapBuilder.eof(); setData(out.toByteArray()); } finally { if (in != null) { in.close(); } } }
private synchronized void loadFileData() throws IOException { if (data != null) { return; } InputStream in = null; try { in = dataSource.open(); ByteArrayOutputStream out = new ByteArrayOutputStream(); addLineOffset(0); // Line 0 starts at offset 0 LineNumberMapBuilder mapBuilder = new LineNumberMapBuilder(this); // Copy all of the data from the file into the byte array output // stream byte[] buf = new byte[1024]; int n; while ((n = in.read(buf)) >= 0) { mapBuilder.addData(buf, n); out.write(buf, 0, n); } mapBuilder.eof(); setData(out.toByteArray()); } finally { if (in != null) { in.close(); } } }