40 |
class BlockOutputStream extends DTPOutputStream |
class BlockOutputStream extends DTPOutputStream |
41 |
{ |
{ |
42 |
|
|
43 |
static final byte RECORD = -128; // 0x80 |
static final byte RECORD = -128; // 0x80 |
44 |
static final byte EOF = 64; // 0x40 |
static final byte EOF = 64; // 0x40 |
45 |
|
|
46 |
BlockOutputStream(DTP dtp, OutputStream out) |
BlockOutputStream(DTP dtp, OutputStream out) |
47 |
{ |
{ |
48 |
super(dtp, out); |
super(dtp, out); |
49 |
} |
} |
50 |
|
|
51 |
public void write(int c) |
public void write(int c) throws IOException |
52 |
throws IOException |
{ |
53 |
{ |
if (transferComplete) |
54 |
if (transferComplete) |
return; |
55 |
return; |
byte[] buf = new byte[] |
56 |
byte[] buf = new byte[] { |
{ |
57 |
RECORD, /* record descriptor */ |
RECORD, /* record descriptor */ |
58 |
0x00, |
0x00, 0x01, /* one byte */ |
59 |
0x01, /* one byte */ |
(byte) c /* the byte */ |
60 |
(byte)c /* the byte */ |
}; |
61 |
}; |
super.write(buf, 0, 4); |
62 |
super.write(buf, 0, 4); |
} |
63 |
} |
|
64 |
|
public void write(byte[]b) throws IOException |
65 |
public void write(byte[] b) |
{ |
66 |
throws IOException |
write(b, 0, b.length); |
67 |
{ |
} |
68 |
write(b, 0, b.length); |
|
69 |
} |
public void write(byte[]b, int off, int len) throws IOException |
70 |
|
{ |
71 |
public void write(byte[] b, int off, int len) |
if (transferComplete) |
72 |
throws IOException |
return; |
73 |
{ |
byte[] buf = new byte[len + 3]; |
74 |
if (transferComplete) |
buf[0] = RECORD; /* record descriptor */ |
75 |
return; |
buf[1] = (byte) ((len & 0x00ff) >> 8); /* high byte of bytecount */ |
76 |
byte[] buf = new byte[len+3]; |
buf[2] = (byte) (len & 0xff00); /* low byte of bytecount */ |
77 |
buf[0] = RECORD; /* record descriptor */ |
System.arraycopy(b, off, buf, 3, len); |
78 |
buf[1] = (byte)((len & 0x00ff) >> 8); /* high byte of bytecount */ |
super.write(buf, 0, len); |
79 |
buf[2] = (byte)(len & 0xff00); /* low byte of bytecount */ |
} |
80 |
System.arraycopy(b, off, buf, 3, len); |
|
81 |
super.write(buf, 0, len); |
public void close() throws IOException |
82 |
} |
{ |
83 |
|
byte[] buf = new byte[] |
84 |
public void close() |
{ |
85 |
throws IOException |
EOF, /* eof descriptor */ |
86 |
{ |
0x00, 0x00 /* no bytes */ |
87 |
byte[] buf = new byte[] { |
}; |
88 |
EOF, /* eof descriptor */ |
super.write(buf, 0, 3); |
89 |
0x00, |
super.close(); |
90 |
0x00 /* no bytes */ |
} |
|
}; |
|
|
super.write(buf, 0, 3); |
|
|
super.close(); |
|
|
} |
|
91 |
|
|
92 |
} |
} |