We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ByteBuffer.allocateDirect(int size) 를 이용한 다이렉트 버퍼를 적용하면 BufferedOutputStream 등 보다 훨씬 빠르게 진행 가능
private void useByteBuffer() throws Exception { String url = "https://github.com/occidere/MMDownloader/releases/download/v0.5.0.6/MMDownloader_0.5.0.6_Mac_Linux.zip"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", "Mozilla/5.0"); File file = new File("C:/Users/occid/Desktop/test1.zip"); InputStream in = conn.getInputStream(); FileChannel outChannel = new FileOutputStream(file).getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(1024); long et, st = System.currentTimeMillis(); int read = 0; while ((read = in.read()) != -1) { if (!buf.hasRemaining()) { buf.flip(); outChannel.write(buf); buf.clear(); } buf.put((byte) read); } buf.flip(); outChannel.write(buf); outChannel.close(); et = System.currentTimeMillis(); System.out.println("ByteBuffer: " + (et - st) + " ms"); }
The text was updated successfully, but these errors were encountered:
occidere
No branches or pull requests
ByteBuffer & FileChannel 이용해볼 것
ByteBuffer.allocateDirect(int size) 를 이용한 다이렉트 버퍼를 적용하면 BufferedOutputStream 등 보다 훨씬 빠르게 진행 가능
참고
The text was updated successfully, but these errors were encountered: