From 1a83b46657501c96b7619b2f66f8b8229d1a2c0c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Mon, 13 Apr 2020 14:03:31 +0200 Subject: [PATCH] Minor code cleanup. --- .../dictionary/engine/ReadAheadBuffer.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) 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[]; } -- 2.43.0