1 |
/* |
/* |
2 |
* $Id$ |
* BlockOutputStream.java |
3 |
* Copyright (C) 2003 The Free Software Foundation |
* Copyright (C) 2003 The Free Software Foundation |
4 |
* |
* |
5 |
* This file is part of GNU inetlib, a library. |
* This file is part of GNU inetlib, a library. |
46 |
* A DTP output stream that implements the FTP block transfer mode. |
* A DTP output stream that implements the FTP block transfer mode. |
47 |
* |
* |
48 |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
|
* @version $Revision$ $Date$ |
|
49 |
*/ |
*/ |
50 |
class BlockOutputStream extends DTPOutputStream |
class BlockOutputStream |
51 |
|
extends DTPOutputStream |
52 |
{ |
{ |
53 |
|
|
54 |
static final byte RECORD = -128; // 0x80 |
static final byte RECORD = -128; // 0x80 |
55 |
static final byte EOF = 64; // 0x40 |
static final byte EOF = 64; // 0x40 |
56 |
|
|
57 |
BlockOutputStream (DTP dtp, OutputStream out) |
BlockOutputStream(DTP dtp, OutputStream out) |
58 |
{ |
{ |
59 |
super (dtp, out); |
super(dtp, out); |
60 |
} |
} |
61 |
|
|
62 |
public void write (int c) throws IOException |
public void write(int c) |
63 |
{ |
throws IOException |
64 |
if (transferComplete) |
{ |
65 |
{ |
if (transferComplete) |
66 |
return; |
{ |
67 |
} |
return; |
68 |
byte[] buf = new byte[] |
} |
69 |
{ |
byte[] buf = new byte[] |
70 |
RECORD, /* record descriptor */ |
{ |
71 |
0x00, 0x01, /* one byte */ |
RECORD, /* record descriptor */ |
72 |
(byte) c /* the byte */ |
0x00, 0x01, /* one byte */ |
73 |
}; |
(byte) c /* the byte */ |
74 |
out.write (buf, 0, 4); |
}; |
75 |
} |
out.write(buf, 0, 4); |
76 |
|
} |
77 |
public void write (byte[] b) throws IOException |
|
78 |
{ |
public void write(byte[] b) |
79 |
write (b, 0, b.length); |
throws IOException |
80 |
} |
{ |
81 |
|
write(b, 0, b.length); |
82 |
public void write (byte[] b, int off, int len) throws IOException |
} |
83 |
{ |
|
84 |
if (transferComplete) |
public void write(byte[] b, int off, int len) |
85 |
{ |
throws IOException |
86 |
return; |
{ |
87 |
} |
if (transferComplete) |
88 |
byte[] buf = new byte[len + 3]; |
{ |
89 |
buf[0] = RECORD; /* record descriptor */ |
return; |
90 |
buf[1] = (byte) ((len & 0x00ff) >> 8); /* high byte of bytecount */ |
} |
91 |
buf[2] = (byte) (len & 0xff00); /* low byte of bytecount */ |
byte[] buf = new byte[len + 3]; |
92 |
System.arraycopy (b, off, buf, 3, len); |
buf[0] = RECORD; /* record descriptor */ |
93 |
out.write (buf, 0, len); |
buf[1] = (byte) ((len & 0x00ff) >> 8); /* high byte of bytecount */ |
94 |
} |
buf[2] = (byte) (len & 0xff00); /* low byte of bytecount */ |
95 |
|
System.arraycopy(b, off, buf, 3, len); |
96 |
public void close () throws IOException |
out.write(buf, 0, len); |
97 |
{ |
} |
98 |
byte[] buf = new byte[] |
|
99 |
{ |
public void close() |
100 |
EOF, /* eof descriptor */ |
throws IOException |
101 |
0x00, 0x00 /* no bytes */ |
{ |
102 |
}; |
byte[] buf = new byte[] |
103 |
out.write (buf, 0, 3); |
{ |
104 |
super.close (); |
EOF, /* eof descriptor */ |
105 |
} |
0x00, 0x00 /* no bytes */ |
106 |
|
}; |
107 |
|
out.write(buf, 0, 3); |
108 |
|
super.close(); |
109 |
|
} |
110 |
|
|
111 |
} |
} |
112 |
|
|