X-Git-Url: http://gitweb.fperrin.net/?p=DictionaryPC.git;a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FReadAheadBuffer.java;h=3c4c10d0aeebf2442a69fda3ba5619e94adc7c8b;hp=d4b3ab51a281ee5a177b0259530ebe8ba7c86c90;hb=1a83b46657501c96b7619b2f66f8b8229d1a2c0c;hpb=2182783b7ac6a22c23b37db4ba458ff12a6978dc diff --git a/src/com/hughes/android/dictionary/engine/ReadAheadBuffer.java b/src/com/hughes/android/dictionary/engine/ReadAheadBuffer.java index d4b3ab5..3c4c10d 100644 --- a/src/com/hughes/android/dictionary/engine/ReadAheadBuffer.java +++ b/src/com/hughes/android/dictionary/engine/ReadAheadBuffer.java @@ -14,8 +14,8 @@ package com.hughes.android.dictionary.engine; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; @@ -24,29 +24,26 @@ public class ReadAheadBuffer extends PipedInputStream { public ReadAheadBuffer(InputStream in, int size) { super(size); assert size >= 2 * BLOCK_SIZE; - this.in = in; try { pipe = new PipedOutputStream(this); - buffer = new byte[BLOCK_SIZE]; - new Thread(new Runnable() { - public void run() { - int read; - try { - while ((read = in.read(buffer)) > 0) - { - pipe.write(buffer, 0, read); - pipe.flush(); - } - } catch (IOException e) {} - try { - pipe.close(); - } catch (IOException e) {} - } - }).start(); } catch (IOException e) {} + new Thread(new Runnable() { + public void run() { + try { + int read; + final byte buffer[] = new byte[BLOCK_SIZE]; + while ((read = in.read(buffer)) > 0) + { + pipe.write(buffer, 0, read); + pipe.flush(); + } + } catch (IOException e) {} + try { + pipe.close(); + } catch (IOException e) {} + } + }).start(); } - InputStream in; PipedOutputStream pipe; - byte buffer[]; }