[kaffe] CVS kaffe (dalibor): Resynced with Tritonus + Merged in FTP handler from GNU Inetlib

Kaffe CVS cvs-commits at kaffe.org
Sat Jan 10 15:41:02 PST 2004


PatchSet 4315 
Date: 2004/01/10 23:34:27
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Resynced with Tritonus + Merged in FTP handler from GNU Inetlib

2004-01-11  Dalibor Topic <robilad at kaffe.org>

        Resynced with Tritonus.org.

        * libraries/javalib/org/tritonus/share/sampled/convert/TAudioInputStream.java:
        New file from Tritonus.

        * libraries/javalib/profiles/default/sound.files:
        Added org/tritonus/share/sampled/convert/TAudioInputStream.java.

        Merged in FTP Handler from GNU Inetlib, licensed under GPL + linking exception.

        libraries/javalib/gnu/inet/ftp/ActiveModeDTP.java,
        libraries/javalib/gnu/inet/ftp/BlockInputStream.java,
        libraries/javalib/gnu/inet/ftp/BlockOutputStream.java,
        libraries/javalib/gnu/inet/ftp/CompressedInputStream.java,
        libraries/javalib/gnu/inet/ftp/CompressedOutputStream.java,
        libraries/javalib/gnu/inet/ftp/DTP.java,
        libraries/javalib/gnu/inet/ftp/DTPInputStream.java,
        libraries/javalib/gnu/inet/ftp/DTPOutputStream.java,
        libraries/javalib/gnu/inet/ftp/FTPConnection.java,
        libraries/javalib/gnu/inet/ftp/FTPException.java,
        libraries/javalib/gnu/inet/ftp/FTPResponse.java,
        libraries/javalib/gnu/inet/ftp/FTPURLConnection.java,
        libraries/javalib/gnu/inet/ftp/FTPURLStreamHandler.java,
        libraries/javalib/gnu/inet/ftp/PassiveModeDTP.java,
        libraries/javalib/gnu/inet/ftp/StreamInputStream.java,
        libraries/javalib/gnu/inet/ftp/StreamOutputStream.java,
        libraries/javalib/gnu/inet/util/CRLFInputStream.java,
        libraries/javalib/gnu/inet/util/LineInputStream.java,
        libraries/javalib/profiles/default/inet.files:
        New files.

        * libraries/javalib/profiles/default/profile:
        Added inet.files.

        * libltdl/config-h.in,
        libraries/javalib/Makefile.am,
        libraries/javalib/Makefile.in,
        libraries/javalib/profiles/allatonce/all.files,
        Regenerated.

Members: 
	ChangeLog:1.1902->1.1903 
	libltdl/config-h.in:1.11->1.12 
	libraries/javalib/Makefile.am:1.155->1.156 
	libraries/javalib/Makefile.in:1.207->1.208 
	libraries/javalib/gnu/inet/ftp/ActiveModeDTP.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/BlockInputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/BlockOutputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/CompressedInputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/CompressedOutputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/DTP.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/DTPInputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/DTPOutputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/FTPConnection.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/FTPException.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/FTPResponse.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/FTPURLConnection.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/FTPURLStreamHandler.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/PassiveModeDTP.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/StreamInputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/ftp/StreamOutputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/util/CRLFInputStream.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/util/LineInputStream.java:INITIAL->1.1 
	libraries/javalib/org/tritonus/share/sampled/convert/TAudioInputStream.java:INITIAL->1.1 
	libraries/javalib/profiles/allatonce/all.files:1.33->1.34 
	libraries/javalib/profiles/default/inet.files:INITIAL->1.1 
	libraries/javalib/profiles/default/profile:1.4->1.5 
	libraries/javalib/profiles/default/sound.files:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1902 kaffe/ChangeLog:1.1903
--- kaffe/ChangeLog:1.1902	Sat Jan 10 22:20:55 2004
+++ kaffe/ChangeLog	Sat Jan 10 23:34:27 2004
@@ -1,3 +1,45 @@
+2004-01-11  Dalibor Topic <robilad at kaffe.org>
+
+	Resynced with Tritonus.org.
+
+        * libraries/javalib/org/tritonus/share/sampled/convert/TAudioInputStream.java:
+	New file from Tritonus.
+
+        * libraries/javalib/profiles/default/sound.files:
+	Added org/tritonus/share/sampled/convert/TAudioInputStream.java.
+
+	Merged in FTP Handler from GNU Inetlib, licensed under GPL + linking exception.
+
+        libraries/javalib/gnu/inet/ftp/ActiveModeDTP.java,
+        libraries/javalib/gnu/inet/ftp/BlockInputStream.java,
+        libraries/javalib/gnu/inet/ftp/BlockOutputStream.java,
+        libraries/javalib/gnu/inet/ftp/CompressedInputStream.java,
+        libraries/javalib/gnu/inet/ftp/CompressedOutputStream.java,
+        libraries/javalib/gnu/inet/ftp/DTP.java,
+        libraries/javalib/gnu/inet/ftp/DTPInputStream.java,
+        libraries/javalib/gnu/inet/ftp/DTPOutputStream.java,
+        libraries/javalib/gnu/inet/ftp/FTPConnection.java,
+        libraries/javalib/gnu/inet/ftp/FTPException.java,
+        libraries/javalib/gnu/inet/ftp/FTPResponse.java,
+        libraries/javalib/gnu/inet/ftp/FTPURLConnection.java,
+        libraries/javalib/gnu/inet/ftp/FTPURLStreamHandler.java,
+        libraries/javalib/gnu/inet/ftp/PassiveModeDTP.java,
+        libraries/javalib/gnu/inet/ftp/StreamInputStream.java,
+        libraries/javalib/gnu/inet/ftp/StreamOutputStream.java,
+        libraries/javalib/gnu/inet/util/CRLFInputStream.java,
+        libraries/javalib/gnu/inet/util/LineInputStream.java,
+        libraries/javalib/profiles/default/inet.files:
+	New files.
+
+	* libraries/javalib/profiles/default/profile:
+	Added inet.files.
+
+ 	* libltdl/config-h.in,
+	libraries/javalib/Makefile.am,
+	libraries/javalib/Makefile.in,
+	libraries/javalib/profiles/allatonce/all.files,
+	Regenerated.
+
 2004-01-10  Dalibor Topic <robilad at kaffe.org>
 
         Resynced with Tritonus.org.
Index: kaffe/libltdl/config-h.in
diff -u kaffe/libltdl/config-h.in:1.11 kaffe/libltdl/config-h.in:1.12
--- kaffe/libltdl/config-h.in:1.11	Thu Jan  8 16:38:47 2004
+++ kaffe/libltdl/config-h.in	Sat Jan 10 23:34:28 2004
@@ -188,8 +188,6 @@
 /* Define to a type to use for `error_t' if it is not otherwise available. */
 #undef error_t
 
-/* Define to `__inline__' or `__inline' if that's what the C compiler
-   calls it, or to nothing if 'inline' is not supported under any name.  */
-#ifndef __cplusplus
+/* Define as `__inline' if that's what the C compiler calls it, or to nothing
+   if it is not supported. */
 #undef inline
-#endif
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.155 kaffe/libraries/javalib/Makefile.am:1.156
--- kaffe/libraries/javalib/Makefile.am:1.155	Thu Jan  8 10:33:51 2004
+++ kaffe/libraries/javalib/Makefile.am	Sat Jan 10 23:34:29 2004
@@ -47,6 +47,8 @@
 
 Klasses_jar_SRCS = \
 	$(gnu_classpath_SRCS) \
+	$(gnu_inet_ftp_SRCS) \
+	$(gnu_inet_util_SRCS) \
 	$(gnu_java_awt_SRCS) \
 	$(gnu_java_beans_SRCS) \
 	$(gnu_java_beans_editors_SRCS) \
@@ -195,6 +197,26 @@
 gnu_classpath_SRCS = \
 	gnu/classpath/Configuration.java \
 	gnu/classpath/RawData.java
+gnu_inet_ftp_SRCS = \
+	gnu/inet/ftp/ActiveModeDTP.java \
+	gnu/inet/ftp/BlockInputStream.java \
+	gnu/inet/ftp/BlockOutputStream.java \
+	gnu/inet/ftp/CompressedInputStream.java \
+	gnu/inet/ftp/CompressedOutputStream.java \
+	gnu/inet/ftp/DTPInputStream.java \
+	gnu/inet/ftp/DTP.java \
+	gnu/inet/ftp/DTPOutputStream.java \
+	gnu/inet/ftp/FTPConnection.java \
+	gnu/inet/ftp/FTPException.java \
+	gnu/inet/ftp/FTPResponse.java \
+	gnu/inet/ftp/FTPURLConnection.java \
+	gnu/inet/ftp/FTPURLStreamHandler.java \
+	gnu/inet/ftp/PassiveModeDTP.java \
+	gnu/inet/ftp/StreamInputStream.java \
+	gnu/inet/ftp/StreamOutputStream.java
+gnu_inet_util_SRCS = \
+	gnu/inet/util/CRLFInputStream.java \
+	gnu/inet/util/LineInputStream.java
 gnu_java_awt_SRCS = \
 	gnu/java/awt/BitMaskExtent.java \
 	gnu/java/awt/Buffers.java \
@@ -2230,6 +2252,7 @@
 	org/tritonus/share/sampled/TVolumeUtils.java
 org_tritonus_share_sampled_convert_SRCS = \
 	org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java \
+	org/tritonus/share/sampled/convert/TAudioInputStream.java \
 	org/tritonus/share/sampled/convert/TEncodingFormatConversionProvider.java \
 	org/tritonus/share/sampled/convert/TFormatConversionProvider.java \
 	org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.207 kaffe/libraries/javalib/Makefile.in:1.208
--- kaffe/libraries/javalib/Makefile.in:1.207	Thu Jan  8 10:33:51 2004
+++ kaffe/libraries/javalib/Makefile.in	Sat Jan 10 23:34:29 2004
@@ -312,6 +312,8 @@
 @HAVE_DNSJAVA_TRUE at DNSJAVA_InetAddressImpl = gnu/java/net/DNSJavaInetAddressImpl.java
 Klasses_jar_SRCS = \
 	$(gnu_classpath_SRCS) \
+	$(gnu_inet_ftp_SRCS) \
+	$(gnu_inet_util_SRCS) \
 	$(gnu_java_awt_SRCS) \
 	$(gnu_java_beans_SRCS) \
 	$(gnu_java_beans_editors_SRCS) \
@@ -462,6 +464,28 @@
 	gnu/classpath/Configuration.java \
 	gnu/classpath/RawData.java
 
+gnu_inet_ftp_SRCS = \
+	gnu/inet/ftp/ActiveModeDTP.java \
+	gnu/inet/ftp/BlockInputStream.java \
+	gnu/inet/ftp/BlockOutputStream.java \
+	gnu/inet/ftp/CompressedInputStream.java \
+	gnu/inet/ftp/CompressedOutputStream.java \
+	gnu/inet/ftp/DTPInputStream.java \
+	gnu/inet/ftp/DTP.java \
+	gnu/inet/ftp/DTPOutputStream.java \
+	gnu/inet/ftp/FTPConnection.java \
+	gnu/inet/ftp/FTPException.java \
+	gnu/inet/ftp/FTPResponse.java \
+	gnu/inet/ftp/FTPURLConnection.java \
+	gnu/inet/ftp/FTPURLStreamHandler.java \
+	gnu/inet/ftp/PassiveModeDTP.java \
+	gnu/inet/ftp/StreamInputStream.java \
+	gnu/inet/ftp/StreamOutputStream.java
+
+gnu_inet_util_SRCS = \
+	gnu/inet/util/CRLFInputStream.java \
+	gnu/inet/util/LineInputStream.java
+
 gnu_java_awt_SRCS = \
 	gnu/java/awt/BitMaskExtent.java \
 	gnu/java/awt/Buffers.java \
@@ -2628,6 +2652,7 @@
 
 org_tritonus_share_sampled_convert_SRCS = \
 	org/tritonus/share/sampled/convert/TAsynchronousFilteredAudioInputStream.java \
+	org/tritonus/share/sampled/convert/TAudioInputStream.java \
 	org/tritonus/share/sampled/convert/TEncodingFormatConversionProvider.java \
 	org/tritonus/share/sampled/convert/TFormatConversionProvider.java \
 	org/tritonus/share/sampled/convert/TMatrixFormatConversionProvider.java \
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/ftp/ActiveModeDTP.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/ftp/ActiveModeDTP.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/ftp/ActiveModeDTP.java	Sat Jan 10 23:38:34 2004
@@ -0,0 +1,204 @@
+/*
+ * $Id: ActiveModeDTP.java,v 1.1 2004/01/10 23:34:30 dalibor Exp $
+ * Copyright (C) 2003 The Free Software Foundation
+ * 
+ * This file is part of GNU inetlib, a library.
+ * 
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * 
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.inet.ftp;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+/**
+ * An active mode FTP data transfer process.
+ * This starts a server on the specified port listening for a data
+ * connection. It converts the socket input into a file stream for reading.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ * @version $Revision: 1.1 $ $Date: 2004/01/10 23:34:30 $
+ */
+final class ActiveModeDTP implements DTP, Runnable
+{
+
+  ServerSocket server;
+  Socket socket;
+  DTPInputStream in;
+  DTPOutputStream out;
+  boolean completed;
+  boolean inProgress;
+  int transferMode;
+  IOException exception;
+  Thread acceptThread;
+
+    ActiveModeDTP(InetAddress localhost, int port) throws IOException
+  {
+    completed = false;
+    inProgress = false;
+    server = new ServerSocket(port, 1, localhost);
+    acceptThread = new Thread(this, "ActiveModeDTP");
+    acceptThread.start();
+  }
+
+        /**
+	 * Start listening.
+	 */
+  public void run()
+  {
+    try
+    {
+      socket = server.accept();
+      //System.err.println("Accepted connection from "+socket.getInetAddress()+":"+socket.getPort());
+    }
+    catch(IOException e)
+    {
+      exception = e;
+    }
+  }
+
+        /**
+	 * Waits until a client has connected.
+	 */
+  public void waitFor() throws IOException
+  {
+    long timeout = 6000;        // TODO review this
+      try
+    {
+      acceptThread.join(timeout);
+    }
+    catch(InterruptedException e)
+    {
+    }
+    if (exception != null)
+      throw exception;
+    if (socket == null)
+    {
+      server.close();
+      throw new IOException("client did not connect before timeout");
+    }
+    acceptThread = null;
+  }
+
+        /**
+	 * Returns an input stream from which a remote file can be read.
+	 */
+  public InputStream getInputStream() throws IOException
+  {
+    if (inProgress)
+      throw new IOException("Transfer in progress");
+    if (acceptThread != null)
+        waitFor();
+    switch (transferMode)
+    {
+    case FTPConnection.MODE_STREAM:
+      in = new StreamInputStream(this, socket.getInputStream());
+      break;
+      case FTPConnection.MODE_BLOCK:in =
+        new BlockInputStream(this, socket.getInputStream());
+      break;
+      case FTPConnection.MODE_COMPRESSED:in =
+        new CompressedInputStream(this, socket.getInputStream());
+      break;
+      default:throw new IllegalStateException("invalid transfer mode");
+    }
+    in.setTransferComplete(false);
+    return in;
+  }
+
+        /**
+	 * Returns an output stream to which a local file can be written for
+	 * upload.
+	 */
+  public OutputStream getOutputStream() throws IOException
+  {
+    if (inProgress)
+      throw new IOException("Transfer in progress");
+    if (acceptThread != null)
+        waitFor();
+    switch (transferMode)
+    {
+    case FTPConnection.MODE_STREAM:
+      out = new StreamOutputStream(this, socket.getOutputStream());
+      break;
+      case FTPConnection.MODE_BLOCK:out =
+        new BlockOutputStream(this, socket.getOutputStream());
+      break;
+      case FTPConnection.MODE_COMPRESSED:out =
+        new CompressedOutputStream(this, socket.getOutputStream());
+      break;
+      default:throw new IllegalStateException("invalid transfer mode");
+    }
+    out.setTransferComplete(false);
+    return out;
+  }
+
+  public void setTransferMode(int mode)
+  {
+    transferMode = mode;
+  }
+
+  public void complete()
+  {
+    completed = true;
+    if (!inProgress)
+      transferComplete();
+  }
+
+  public boolean abort()
+  {
+    completed = true;
+    transferComplete();
+    return inProgress;
+  }
+
+  public void transferComplete()
+  {
+    if (socket == null)
+      return;
+    in.setTransferComplete(true);
+    out.setTransferComplete(true);
+    completed = completed || (transferMode == FTPConnection.MODE_STREAM);
+    if (completed)
+    {
+      try
+      {
+        socket.close();
+      }
+      catch(IOException e)
+      {
+      }
+      try
+      {
+        server.close();
+      }
+      catch(IOException e)
+      {
+      }
+    }
+  }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/ftp/BlockInputStream.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/ftp/BlockInputStream.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/ftp/BlockInputStream.java	Sat Jan 10 23:38:34 2004
@@ -0,0 +1,119 @@
+/*
+ * $Id: BlockInputStream.java,v 1.1 2004/01/10 23:34:31 dalibor Exp $
+ * Copyright (C) 2003 The Free Software Foundation
+ * 
+ * This file is part of GNU inetlib, a library.
+ * 
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * 
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.inet.ftp;
+
+import java.io.FilterInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * A DTP input stream that implements the FTP block transfer mode.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ * @version $Revision: 1.1 $ $Date: 2004/01/10 23:34:31 $
+ */
+class BlockInputStream extends DTPInputStream
+{
+
+    static final int EOF = 64;
+    
+    int descriptor;
+    int max = -1;
+    int count = -1;
+    
+    BlockInputStream(DTP dtp, InputStream in)
+    {
+        super(dtp, in);
+    }
+    
+    public int read() throws IOException
+    {
+        if (transferComplete)
+            return -1;
+        if (count == -1)
+            readHeader();
+        if (max < 1)
+        {
+            close();
+            return -1;
+        }
+        int c = in.read();
+        if (c == -1)
+            dtp.transferComplete();
+        count++;
+        if (count >= max)
+        {
+            count = -1;
+            if (descriptor == EOF)
+                close();
+        }
+        return c;
+    }
+
+    public int read(byte[] buf) throws IOException
+    {
+        return read(buf, 0, buf.length);
+    }
+    
+    public int read(byte[] buf, int off, int len) throws IOException
+    {
+        if (transferComplete)
+            return -1;
+        if (count == -1)
+            readHeader();
+        if (max < 1)
+        {
+            close();
+            return -1;
+        }
+        int l = in.read(buf, off, len);
+        if (l == -1)
+            dtp.transferComplete();
+        count += l;
+        if (count >= max)
+        {
+            count = -1;
+            if (descriptor == EOF)
+                close();
+        }
+        return l;
+    }
+    
+    /**
+     * Reads the block header.
+     */
+    void readHeader() throws IOException
+    {
+        descriptor = in.read();
+        int max_hi = in.read();
+        int max_lo = in.read();
+        max = (max_hi << 8) | max_lo;
+        count = 0;
+    }
+    
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/ftp/BlockOutputStream.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/ftp/BlockOutputStream.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/ftp/BlockOutputStream.java	Sat Jan 10 23:38:34 2004
@@ -0,0 +1,92 @@
+/*
+ * $Id: BlockOutputStream.java,v 1.1 2004/01/10 23:34:31 dalibor Exp $
+ * Copyright (C) 2003 The Free Software Foundation
+ * 
+ * This file is part of GNU inetlib, a library.
+ * 
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * 
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.inet.ftp;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A DTP output stream that implements the FTP block transfer mode.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ * @version $Revision: 1.1 $ $Date: 2004/01/10 23:34:31 $
+ */
+class BlockOutputStream extends DTPOutputStream
+{
+
+    static final byte RECORD = -128;      // 0x80
+    static final byte EOF = 64;   // 0x40
+    
+    BlockOutputStream(DTP dtp, OutputStream out)
+    {
+        super(dtp, out);
+    }
+    
+    public void write(int c) throws IOException
+    {
+        if (transferComplete)
+            return;
+        byte[] buf = new byte[]
+        {
+            RECORD,                   /* record descriptor */
+            0x00, 0x01,             /* one byte */
+            (byte) c                /* the byte */
+        };
+        out.write(buf, 0, 4);
+    }
+
+    public void write(byte[] b) throws IOException
+    {
+        write(b, 0, b.length);
+    }
+    
+    public void write(byte[] b, int off, int len) throws IOException
+    {
+        if (transferComplete)
+            return;
+        byte[] buf = new byte[len + 3];
+        buf[0] = RECORD;            /* record descriptor */
+        buf[1] = (byte) ((len & 0x00ff) >> 8);      /* high byte of bytecount */
+        buf[2] = (byte) (len & 0xff00);     /* low byte of bytecount */
+        System.arraycopy(b, off, buf, 3, len);
+        out.write(buf, 0, len);
+    }
+    
+    public void close() throws IOException
+    {
+        byte[] buf = new byte[]
+        {
+            EOF,                      /* eof descriptor */
+            0x00, 0x00              /* no bytes */
+        };
+        out.write(buf, 0, 3);
+        super.close();
+    }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/ftp/CompressedInputStream.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/ftp/CompressedInputStream.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/ftp/CompressedInputStream.java	Sat Jan 10 23:38:34 2004
@@ -0,0 +1,178 @@
+/*
+ * $Id: CompressedInputStream.java,v 1.1 2004/01/10 23:34:31 dalibor Exp $
+ * Copyright (C) 2003 The Free Software Foundation
+ * 
+ * This file is part of GNU inetlib, a library.
+ * 
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * 
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.inet.ftp;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.ProtocolException;
+
+/**
+ * A DTP input stream that implements the FTP compressed transfer mode.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ * @version $Revision: 1.1 $ $Date: 2004/01/10 23:34:31 $
+ */
+class CompressedInputStream extends DTPInputStream
+{
+
+    static final int EOF = 64;
+    
+    static final int RAW = 0x00;
+    static final int COMPRESSED = 0x80;
+    static final int FILLER = 0xc0;
+    
+    int descriptor;
+    int max = -1;
+    int count = -1;
+    
+    int state = RAW;              // RAW | STATE | FILLER
+    int rep;                      // the compressed byte
+    int n = 0;                    // the number of compressed or raw bytes
+    
+    CompressedInputStream(DTP dtp, InputStream in)
+    {
+        super(dtp, in);
+    }
+    
+    public int read() throws IOException
+    {
+        if (transferComplete)
+            return -1;
+        if (count == -1)
+            readHeader();
+        if (max < 1)
+        {
+            close();
+            return -1;
+        }
+        if (n > 0 && (state == COMPRESSED || state == FILLER))
+        {
+            n--;
+            return rep;
+        }
+        int c = in.read();
+        if (c == -1)
+            close();
+        count++;
+        if (count >= max)
+        {
+            count = -1;
+            if (descriptor == EOF)
+                close();
+        }
+        if (c == -1)
+            return c;
+        while (n == 0)              // read code header
+        {
+            state = (c & 0xc0);
+            n = (c & 0x3f);
+            c = in.read();
+            if (c == -1)
+                return -1;
+        }
+        switch (state)
+        {
+          case RAW:
+            break;
+          case COMPRESSED:
+          case FILLER:
+            rep = c;
+            break;
+          default:
+            throw new ProtocolException("Illegal state: " + state);
+        }
+        n--;
+        return c;
+    }
+    
+    public int read(byte[] buf) throws IOException
+    {
+        return read(buf, 0, buf.length);
+    }
+    
+    public int read(byte[] buf, int off, int len) throws IOException
+    {
+        if (transferComplete)
+            return -1;
+        if (count == -1)
+            readHeader();
+        if (max < 1)
+        {
+            close();
+            return -1;
+        }
+        // TODO improve performance
+        for (int i = off; i < len; i++)
+        {
+            int c = read();
+            if (c == -1)
+            {
+                close();
+                return i;
+            }
+            buf[i] = (byte) c;
+        }
+        return len;
+        /*
+           int l = in.read(buf, off, len);
+           if (l==-1)
+           close();
+           count += l;
+           if (count>=max)
+           {
+           count = -1;
+           if (descriptor==EOF)
+           close();
+           }
+           return l;
+           */
+    }
+    
+    /**
+     * Reads the block header.
+     */
+    void readHeader() throws IOException
+    {
+        descriptor = in.read();
+        int max_hi = in.read();
+        int max_lo = in.read();
+        max = (max_hi << 8) | max_lo;
+        count = 0;
+    }
+    
+    /**
+     * Reads the code header.
+     */
+    void readCodeHeader() throws IOException
+    {
+        int code = in.read();
+        state = (code & 0xc0);
+        n = (code & 0x3f);
+    }
+    
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/ftp/CompressedOutputStream.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/ftp/CompressedOutputStream.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/ftp/CompressedOutputStream.java	Sat Jan 10 23:38:34 2004
@@ -0,0 +1,196 @@
+/*
+ * $Id: CompressedOutputStream.java,v 1.1 2004/01/10 23:34:31 dalibor Exp $
+ * Copyright (C) 2003 The Free Software Foundation
+ * 
+ * This file is part of GNU inetlib, a library.
+ * 
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * 
+ * As a special exception, if you link this library with other files to
+ * produce an executable, this library does not by itself cause the
+ * resulting executable to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons why the
+ * executable file might be covered by the GNU General Public License.
+ */
+
+package gnu.inet.ftp;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A DTP output stream that implements the FTP compressed transfer mode.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ * @version $Revision: 1.1 $ $Date: 2004/01/10 23:34:31 $
+ */
+class CompressedOutputStream extends DTPOutputStream
+{
+
+    static final byte RECORD = -128;      // 0x80
+    static final byte EOF = 64;   // 0x40
+    
+    CompressedOutputStream(DTP dtp, OutputStream out)
+    {
+        super(dtp, out);
+    }
+    
+    /**
+     * Just one byte cannot be compressed.
+     * It takes 5 bytes to transmit - hardly very compressed!
+     */
+    public void write(int c) throws IOException
+    {
+        if (transferComplete)
+            return;
+        byte[] buf = new byte[]
+        {
+            RECORD,                   /* record descriptor */
+            0x00, 0x01,             /* one byte */
+            0x01,                   /* one uncompressed byte */
+            (byte) c                /* the byte */
+        };
+        out.write(buf, 0, 5);
+    }
+    
+    public void write(byte[] b) throws IOException
+    {
+        write(b, 0, b.length);
+    }
+
+    /**
+     * The larger len is, the better.
+     */
+    public void write(byte[] b, int off, int len) throws IOException
+    {
+        if (transferComplete)
+            return;
+        byte[] buf = compress(b, off, len);
+        len = buf.length;
+        buf[0] = RECORD;            /* record descriptor */
+        buf[1] = (byte) ((len & 0x00ff) >> 8);      /* high byte of bytecount */
+        buf[2] = (byte) (len & 0xff00);     /* low byte of bytecount */
+        out.write(buf, 0, len);
+    }
+    
+    /**
+     * Returns the compressed form of the given byte array.
+     * The first 3 bytes are left free for header information.
+     */
+    byte[] compress(byte[] b, int off, int len)
+    {
+        byte[] buf = new byte[len];
+        byte last = 0;
+        int pos = 0, raw_count = 0, rep_count = 1;
+        for (int i = off; i < len; i++)
+        {
+            byte c = b[i];
+            if (i > off && c == last) // compress
+            {
+                if (raw_count > 0)      // flush raw bytes to buf
+                {
+                    // need to add raw_count+1 bytes
+                    if (pos + (raw_count + 1) > buf.length)
+                        buf = realloc(buf, len);
+                    pos = flush_raw(buf, pos, b, (i - raw_count) - 1, raw_count);
+                    raw_count = 0;
+                }
+                rep_count++;            // keep looking for same byte
+            }
+            else
+            {
+                if (rep_count > 1)      // flush compressed bytes to buf
+                {
+                    // need to add 2 bytes
+                    if (pos + 2 > buf.length)
+                        buf = realloc(buf, len);
+                    pos = flush_compressed(buf, pos, rep_count, last);
+                    rep_count = 1;
+                }
+                raw_count++;            // keep looking for raw bytes
+            }
+            if (rep_count == 127)     // flush compressed bytes

*** Patch too long, truncated ***




More information about the kaffe mailing list