| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.io; |
| 18 |
|
| 19 |
import java.io.FilterOutputStream; |
| 20 |
import java.io.IOException; |
| 21 |
import java.io.OutputStream; |
| 22 |
|
| 23 |
import uk.me.parabola.imgfmt.ExitException; |
| 24 |
import uk.me.parabola.imgfmt.app.labelenc.CharacterEncoder; |
| 25 |
import uk.me.parabola.imgfmt.app.labelenc.EncodedText; |
| 26 |
|
| 27 |
import static uk.me.parabola.imgfmt.app.labelenc.BaseEncoder.NO_TEXT; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class StructuredOutputStream extends FilterOutputStream { |
| 36 |
|
| 37 |
private final CharacterEncoder encoder; |
| 38 |
|
| 39 |
public StructuredOutputStream(OutputStream out, CharacterEncoder encoder) { |
| 40 |
super(out); |
| 41 |
this.encoder = encoder; |
| 42 |
} |
| 43 |
|
| 44 |
public void write(int b) throws IOException { |
| 45 |
out.write(b); |
| 46 |
} |
| 47 |
|
| 48 |
public void write2(int b) throws IOException { |
| 49 |
out.write(b); |
| 50 |
out.write(b >> 8); |
| 51 |
} |
| 52 |
|
| 53 |
public void write3(int i) throws IOException { |
| 54 |
out.write(i); |
| 55 |
out.write(i >> 8); |
| 56 |
out.write(i >> 16); |
| 57 |
} |
| 58 |
|
| 59 |
public void write4(int b) throws IOException { |
| 60 |
out.write(b); |
| 61 |
out.write(b >> 8); |
| 62 |
out.write(b >> 16); |
| 63 |
out.write(b >> 24); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public void writeString(String s) throws IOException { |
| 75 |
if (encoder == null) |
| 76 |
throw new ExitException("tdbfile: character encoding is null"); |
| 77 |
|
| 78 |
EncodedText encodedText = encoder.encodeText(s); |
| 79 |
if (encodedText == NO_TEXT) |
| 80 |
return; |
| 81 |
|
| 82 |
out.write(encodedText.getCtext(), 0, encodedText.getLength()); |
| 83 |
} |
| 84 |
} |