X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FWriteBuffer.java;h=09e2655ffa88dbf19a13b1831ecc30c0a228dd15;hb=6bdac65cd6138f8660de4f248b32c35fcd748ae7;hp=c68264ebb583523283039adb9a70a313e207b6dd;hpb=863fc804a6496c920a2b2045913c45f938bb646c;p=DictionaryPC.git diff --git a/src/com/hughes/android/dictionary/engine/WriteBuffer.java b/src/com/hughes/android/dictionary/engine/WriteBuffer.java index c68264e..09e2655 100644 --- a/src/com/hughes/android/dictionary/engine/WriteBuffer.java +++ b/src/com/hughes/android/dictionary/engine/WriteBuffer.java @@ -14,35 +14,33 @@ package com.hughes.android.dictionary.engine; -import java.io.OutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; public class WriteBuffer extends PipedOutputStream { - static int BLOCK_SIZE = 1024 * 1024; + static int BLOCK_SIZE = 256 * 1024; public WriteBuffer(OutputStream out, int size) { assert size >= 2 * BLOCK_SIZE; this.out = out; try { pipe = new PipedInputStream(this, size); buffer = new byte[BLOCK_SIZE]; - writeThread = new Thread(new Runnable() { - public void run() { - int read; - try { - while ((read = pipe.read(buffer)) > 0) - { - out.write(buffer, 0, read); - out.flush(); - } - } catch (IOException e) { - System.out.println("Error writing to file " + e); + writeThread = new Thread(() -> { + int read; + try { + while ((read = pipe.read(buffer)) > 0) + { + out.write(buffer, 0, read); + out.flush(); } - try { - out.close(); - } catch (IOException e) {} + } catch (IOException e) { + System.out.println("Error writing to file " + e); } + try { + out.close(); + } catch (IOException e) {} }); writeThread.start(); } catch (IOException e) {} @@ -61,5 +59,5 @@ public class WriteBuffer extends PipedOutputStream { Thread writeThread; OutputStream out; PipedInputStream pipe; - byte buffer[]; + byte[] buffer; }