changeset 257:cc1d3de0e80b

Fix: make ImageLoader.save work
author Frank Benoit <benoit@tionex.de>
date Tue, 24 Jun 2008 22:12:18 +0200
parents 8d1948844918
children 0389eeb717f8 c0d810de7093
files dwt/dwthelper/ByteArrayOutputStream.d dwt/dwthelper/FileOutputStream.d dwt/dwthelper/OutputStream.d
diffstat 3 files changed, 33 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dwthelper/ByteArrayOutputStream.d	Fri Jun 20 15:03:54 2008 +0200
+++ b/dwt/dwthelper/ByteArrayOutputStream.d	Tue Jun 24 22:12:18 2008 +0200
@@ -5,25 +5,32 @@
 
 public import dwt.dwthelper.OutputStream;
 import dwt.dwthelper.utils;
+import tango.io.GrowBuffer;
 
 public class ByteArrayOutputStream : dwt.dwthelper.OutputStream.OutputStream {
 
-    alias dwt.dwthelper.OutputStream.OutputStream.write write;
+    protected GrowBuffer buffer;
 
-    protected byte[] buf;
-    protected int count;
     public this (){
+        buffer = new GrowBuffer();
     }
 
     public this ( int par_size ){
+        buffer = new GrowBuffer(par_size);
     }
 
-    public synchronized void write( int b ){
-        implMissing( __FILE__, __LINE__ );
+    public synchronized override void write( int b ){
+        byte[1] a;
+        a[0] = b & 0xFF;
+        buffer.append(a);
     }
 
-    public synchronized void write( byte[] b, int off, int len ){
-        implMissing( __FILE__, __LINE__ );
+    public synchronized override void write( byte[] b, int off, int len ){
+        buffer.append( b[ off .. off + len ]);
+    }
+
+    public synchronized override void write( byte[] b ){
+        buffer.append( b );
     }
 
     public synchronized void writeTo( dwt.dwthelper.OutputStream.OutputStream out_KEYWORDESCAPE ){
@@ -35,8 +42,7 @@
     }
 
     public synchronized byte[] toByteArray(){
-        implMissing( __FILE__, __LINE__ );
-        return null;
+        return cast(byte[])buffer.slice();
     }
 
     public int size(){
@@ -62,8 +68,6 @@
     public  override void close(){
         implMissing( __FILE__, __LINE__ );
     }
-
-
 }
 
 
--- a/dwt/dwthelper/FileOutputStream.d	Fri Jun 20 15:03:54 2008 +0200
+++ b/dwt/dwthelper/FileOutputStream.d	Tue Jun 24 22:12:18 2008 +0200
@@ -8,41 +8,38 @@
 
 import dwt.dwthelper.utils;
 
+import tango.io.FileConduit;
+
 public class FileOutputStream : dwt.dwthelper.OutputStream.OutputStream {
 
     alias dwt.dwthelper.OutputStream.OutputStream.write write;
     alias dwt.dwthelper.OutputStream.OutputStream.close close;
-
+    FileConduit fc;
+    
     public this ( String name ){
-        implMissing( __FILE__, __LINE__ );
+        fc = new FileConduit( name, FileConduit.WriteCreate );
     }
 
     public this ( String name, bool append ){
-        implMissing( __FILE__, __LINE__ );
+        fc = new FileConduit( name, append ? FileConduit.WriteAppending : FileConduit.WriteCreate );
     }
 
     public this ( dwt.dwthelper.File.File file ){
-        implMissing( __FILE__, __LINE__ );
+        this( file.toString );
     }
 
     public this ( dwt.dwthelper.File.File file, bool append ){
-        implMissing( __FILE__, __LINE__ );
-    }
-
-    public void write( int b ){
-        implMissing( __FILE__, __LINE__ );
+        this( file.toString, append );
     }
 
-    public void write( byte[] b ){
-        implMissing( __FILE__, __LINE__ );
+    public override void write( int b ){
+        ubyte[1] a;
+        a[0] = b & 0xFF;
+        fc.write(a);
     }
 
-    public void write( byte[] b, int off, int len ){
-        implMissing( __FILE__, __LINE__ );
-    }
-
-    public void close(){
-        implMissing( __FILE__, __LINE__ );
+    public override void close(){
+        fc.close();
     }
 
     public void finalize(){
--- a/dwt/dwthelper/OutputStream.d	Fri Jun 20 15:03:54 2008 +0200
+++ b/dwt/dwthelper/OutputStream.d	Tue Jun 24 22:12:18 2008 +0200
@@ -4,47 +4,29 @@
 module dwt.dwthelper.OutputStream;
 
 import dwt.dwthelper.utils;
-static import tango.io.model.IConduit;
 
 public abstract class OutputStream {
 
-    private tango.io.model.IConduit.OutputStream ostr;
-
     public this(){
     }
 
-    protected this( tango.io.model.IConduit.OutputStream aOutStream) {
-        this.ostr = aOutStream;
-    }
-
-    protected this(OutputStream rhs) {
-        ostr = rhs.ostr;
-    }
-
     public abstract void write( int b );
 
     public void write( byte[] b ){
-        ostr.write(b);
-    }
-
-    public void write(String c) {
-        ostr.write(c);
+        foreach( bv; b ){
+            write(bv);
+        }
     }
 
     public void write( byte[] b, int off, int len ){
-        implMissing( __FILE__, __LINE__ );
+        write(b[off .. off+len]);
     }
 
     public void flush(){
-        ostr.flush();
     }
 
     public void close(){
-        ostr.flush();
-        implMissing( __FILE__, __LINE__ );
     }
-
-
 }