/[classpath]/inetlib/source/gnu/inet/ftp/BlockInputStream.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/ftp/BlockInputStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dog, Sun Oct 19 08:51:37 2003 UTC revision 1.2 by dog, Sun Oct 19 16:16:49 2003 UTC
# Line 40  import java.io.IOException; Line 40  import java.io.IOException;
40  class BlockInputStream extends DTPInputStream  class BlockInputStream extends DTPInputStream
41  {  {
42    
43          static final int EOF = 64;    static final int EOF = 64;
44    
45          int descriptor;    int descriptor;
46          int max = -1;    int max = -1;
47          int count = -1;    int count = -1;
48    
49          BlockInputStream(DTP dtp, InputStream in)      BlockInputStream(DTP dtp, InputStream in)
50          {    {
51                  super(dtp, in);      super(dtp, in);
52          }    }
53    
54          public int read()    public int read() throws IOException
55                  throws IOException    {
56          {      if (transferComplete)
57                  if (transferComplete)        return -1;
58                          return -1;      if (count == -1)
59                  if (count==-1)        readHeader();
60                          readHeader();      if (max < 1)
61                  if (max<1)      {
62                  {        close();
63                          close();        return -1;
64                          return -1;      }
65                  }      int c = super.read();
66                  int c = super.read();      if (c == -1)
67                  if (c==-1)        dtp.transferComplete();
68                          dtp.transferComplete();      count++;
69                  count++;      if (count >= max)
70                  if (count>=max)      {
71                  {        count = -1;
72                          count = -1;        if (descriptor == EOF)
73                          if (descriptor==EOF)          close();
74                                  close();      }
75                  }      return c;
76                  return c;    }
77          }  
78      public int read(byte[]buf) throws IOException
79          public int read(byte[] buf)    {
80                  throws IOException      return read(buf, 0, buf.length);
81          {    }
82                  return read(buf, 0, buf.length);  
83          }    public int read(byte[]buf, int off, int len) throws IOException
84      {
85          public int read(byte[] buf, int off, int len)      if (transferComplete)
86                  throws IOException        return -1;
87          {      if (count == -1)
88                  if (transferComplete)        readHeader();
89                          return -1;      if (max < 1)
90                  if (count==-1)      {
91                          readHeader();        close();
92                  if (max<1)        return -1;
93                  {      }
94                          close();      int l = super.read(buf, off, len);
95                          return -1;      if (l == -1)
96                  }        dtp.transferComplete();
97                  int l = super.read(buf, off, len);      count += l;
98                  if (l==-1)      if (count >= max)
99                          dtp.transferComplete();      {
100                  count += l;        count = -1;
101                  if (count>=max)        if (descriptor == EOF)
102                  {          close();
103                          count = -1;      }
104                          if (descriptor==EOF)      return l;
105                                  close();    }
                 }  
                 return l;  
         }  
106    
107          /**          /**
108           * Reads the block header.           * Reads the block header.
109           */           */
110          void readHeader()    void readHeader() throws IOException
111                  throws IOException    {
112          {      descriptor = super.read();
113                  descriptor = super.read();      int max_hi = super.read();
114                  int max_hi = super.read();      int max_lo = super.read();
115                  int max_lo = super.read();        max = (max_hi << 8) | max_lo;
116                  max = (max_hi<<8) | max_lo;        count = 0;
117                  count = 0;    }
118          }  
           
119  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26