|
@@ -30,6 +30,8 @@ public class ByteWriter extends Writer {
|
|
|
char[] chars;
|
|
char[] chars;
|
|
|
byte[] bytes;
|
|
byte[] bytes;
|
|
|
|
|
|
|
|
|
|
+ boolean inUse; // 支持 reentrant
|
|
|
|
|
+
|
|
|
public ByteWriter(Encoder encoder, int bufferSize) {
|
|
public ByteWriter(Encoder encoder, int bufferSize) {
|
|
|
this.encoder = encoder;
|
|
this.encoder = encoder;
|
|
|
this.chars = new char[bufferSize];
|
|
this.chars = new char[bufferSize];
|
|
@@ -37,18 +39,24 @@ public class ByteWriter extends Writer {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public ByteWriter init(OutputStream outputStream) {
|
|
public ByteWriter init(OutputStream outputStream) {
|
|
|
|
|
+ inUse = true;
|
|
|
this.out = outputStream;
|
|
this.out = outputStream;
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void flush() throws IOException {
|
|
|
|
|
- out.flush();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public void close() {
|
|
public void close() {
|
|
|
|
|
+ inUse = false;
|
|
|
out = null;
|
|
out = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public boolean isInUse() {
|
|
|
|
|
+ return inUse;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void flush() throws IOException {
|
|
|
|
|
+ out.flush();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void write(String str, int offset, int len) throws IOException {
|
|
public void write(String str, int offset, int len) throws IOException {
|
|
|
int size, byteLen;
|
|
int size, byteLen;
|
|
|
while (len > 0) {
|
|
while (len > 0) {
|