@Test public void testCopyRafB() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ucar.unidata.io.RandomAccessFile raf = new ucar.unidata.io.RandomAccessFile(TestNcmlRead.topDir + "aggExisting.xml", "r"); IO.copyRafB(raf, 11, 44, out, new byte[10]); assertThat(out.toByteArray()).hasLength(44); }
public static long copyRafB(ucar.unidata.io.RandomAccessFile raf, long offset, long length, OutputStream out, byte[] buffer) throws IOException { int bufferSize = buffer.length; long want = length; raf.seek(offset); while (want > 0) { int len = (int) Math.min(want, bufferSize); int bytesRead = raf.read(buffer, 0, len); if (bytesRead <= 0) break; out.write(buffer, 0, bytesRead); want -= bytesRead; } out.flush(); return length - want; }
IO { public static long copyRafB(ucar.unidata.io.RandomAccessFile raf, long offset, long length, OutputStream out, byte[] buffer) throws IOException { int bufferSize = buffer.length; long want = length; raf.seek(offset); while (want > 0) { int len = (int) Math.min(want, bufferSize); int bytesRead = raf.read(buffer, 0, len); if (bytesRead <= 0) break; out.write(buffer, 0, bytesRead); want -= bytesRead; } out.flush(); return length - want; } }
IO { public static long copyRafB(ucar.unidata.io.RandomAccessFile raf, long offset, long length, OutputStream out, byte[] buffer) throws IOException { int bufferSize = buffer.length; long want = length; raf.seek(offset); while (want > 0) { int len = (int) Math.min(want, bufferSize); int bytesRead = raf.read(buffer, 0, len); if (bytesRead <= 0) break; out.write(buffer, 0, bytesRead); want -= bytesRead; } out.flush(); return length - want; }  }
IO { public static long copyRafB(ucar.unidata.io.RandomAccessFile raf, long offset, long length, OutputStream out, byte[] buffer) throws IOException { int bufferSize = buffer.length; long want = length; raf.seek(offset); while (want > 0) { int len = (int) Math.min(want, bufferSize); int bytesRead = raf.read(buffer, 0, len); if (bytesRead <= 0) break; out.write(buffer, 0, bytesRead); want -= bytesRead; } out.flush(); return length - want; }  @Nullable static InputStream getFileResource(String resourcePath); static long copy(InputStream in, OutputStream out); static long copyBuffered(InputStream in, OutputStream out, int buffer_size); static long copy2null(InputStream in, int buffersize); static long copy2null(FileChannel in, int buffersize); static long copyB(InputStream in, OutputStream out, int bufferSize); static void copyMaxBytes(InputStream in, OutputStream out, int maxBytes); static String readContents(InputStream is); static String readContents(InputStream is, String charset); static byte[] readContentsToByteArray(InputStream is); static void writeContents(String contents, OutputStream os); static void copyFile(String fileInName, String fileOutName); static void copyFile(File fileIn, File fileOut); static void copy2File(byte[] src, String fileOut); static void copyFile(String fileInName, OutputStream out); static void copyFileB(File fileIn, OutputStream out, int bufferSize); static long copyRafB(ucar.unidata.io.RandomAccessFile raf, long offset, long length, OutputStream out,
      byte[] buffer); static void copyDirTree(String fromDirName, String toDirName); static byte[] readFileToByteArray(String filename); static String readFile(String filename); static void writeToFile(String contents, File file); static void writeToFile(byte[] contents, File file); static void writeToFile(String contents, String fileOutName); static long writeToFile(InputStream in, String fileOutName); static long appendToFile(InputStream in, String fileOutName); }
IO { public static long copyRafB(ucar.unidata.io.RandomAccessFile raf, long offset, long length, OutputStream out, byte[] buffer) throws IOException { int bufferSize = buffer.length; long want = length; raf.seek(offset); while (want > 0) { int len = (int) Math.min(want, bufferSize); int bytesRead = raf.read(buffer, 0, len); if (bytesRead <= 0) break; out.write(buffer, 0, bytesRead); want -= bytesRead; } out.flush(); return length - want; }  @Nullable static InputStream getFileResource(String resourcePath); static long copy(InputStream in, OutputStream out); static long copyBuffered(InputStream in, OutputStream out, int buffer_size); static long copy2null(InputStream in, int buffersize); static long copy2null(FileChannel in, int buffersize); static long copyB(InputStream in, OutputStream out, int bufferSize); static void copyMaxBytes(InputStream in, OutputStream out, int maxBytes); static String readContents(InputStream is); static String readContents(InputStream is, String charset); static byte[] readContentsToByteArray(InputStream is); static void writeContents(String contents, OutputStream os); static void copyFile(String fileInName, String fileOutName); static void copyFile(File fileIn, File fileOut); static void copy2File(byte[] src, String fileOut); static void copyFile(String fileInName, OutputStream out); static void copyFileB(File fileIn, OutputStream out, int bufferSize); static long copyRafB(ucar.unidata.io.RandomAccessFile raf, long offset, long length, OutputStream out,
      byte[] buffer); static void copyDirTree(String fromDirName, String toDirName); static byte[] readFileToByteArray(String filename); static String readFile(String filename); static void writeToFile(String contents, File file); static void writeToFile(byte[] contents, File file); static void writeToFile(String contents, String fileOutName); static long writeToFile(InputStream in, String fileOutName); static long appendToFile(InputStream in, String fileOutName); static final int default_file_buffersize; static final int default_socket_buffersize; }