diff dwt/internal/image/PngInputStream.d @ 34:5123b17c98ef

Ported dwt.events.*, dwt.graphics.GC, Region, dwt.internal.image.*
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sun, 14 Sep 2008 01:45:57 +0200
parents b903c16b6f48
children
line wrap: on
line diff
--- a/dwt/internal/image/PngInputStream.d	Fri Sep 12 13:53:21 2008 +0200
+++ b/dwt/internal/image/PngInputStream.d	Sun Sep 14 01:45:57 2008 +0200
@@ -7,19 +7,30 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.internal.image;
+module dwt.internal.image.PngInputStream;
 
-import java.io.IOException;
-import java.io.InputStream;
+import dwt.dwthelper.InputStream;
+import dwt.dwthelper.System;
+import dwt.internal.image.PngIdatChunk;
+import dwt.internal.image.PngChunkReader;
+import dwt.internal.image.PngChunk;
+
+import tango.core.Exception;
+import Math = tango.math.Math;
 
 public class PngInputStream : InputStream {
+
+    alias InputStream.read read;
+
     PngChunkReader reader;
     PngChunk chunk;
     int offset, length;
-    
-    final static int DATA_OFFSET = 8; 
-    
+
+    final static int DATA_OFFSET = 8;
+
 public this(PngIdatChunk chunk, PngChunkReader reader) {
     this.chunk = chunk;
     this.reader = reader;
@@ -27,32 +38,32 @@
     offset = 0;
 }
 
-private bool checkChunk() {
+private bool checkChunk()  {
     while (offset is length) {
         chunk = reader.readNextChunk();
-        if (chunk is null) throw new IOException();
+        if (chunk is null) throw new IOException("no data");
         if (chunk.getChunkType() is PngChunk.CHUNK_IEND) return false;
-        if (chunk.getChunkType() !is PngChunk.CHUNK_IDAT) throw new IOException();
+        if (chunk.getChunkType() !is PngChunk.CHUNK_IDAT) throw new IOException("");
         length = chunk.getLength();
         offset = 0;
     }
     return true;
 }
 
-public void close() {
+public override void close()  {
     chunk = null;
 }
 
-public int read() {
-    if (chunk is null) throw new IOException();
+public override int read()  {
+    if (chunk is null) throw new IOException("");
     if (offset is length && !checkChunk()) return -1;
     int b = chunk.reference[DATA_OFFSET + offset] & 0xFF;
     offset++;
     return b;
 }
 
-public int read(byte[] b, int off, int len) {
-    if (chunk is null) throw new IOException();
+public override int read(byte[] b, int off, int len)  {
+    if (chunk is null) throw new IOException("");
     if (offset is length && !checkChunk()) return -1;
     len = Math.min(len, length - offset);
     System.arraycopy(chunk.reference, DATA_OFFSET + offset, b, off, len);