01: package org.enhydra.snapper.parsers.fileparsers.parsers.office2007opc;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.IOException;
05: import java.io.OutputStream;
06:
07: /**
08: * Créé un flux de sortie pour les parties de type MemoryPackagePart.
09: *
10: * @author Julien Chable
11: */
12: public final class MemoryPackagePartOutputStream extends OutputStream {
13:
14: private MemoryPackagePart part;
15:
16: private ByteArrayOutputStream buff;
17:
18: public MemoryPackagePartOutputStream(MemoryPackagePart part) {
19: this .part = part;
20: buff = new ByteArrayOutputStream();
21: }
22:
23: @Override
24: public void write(int b) throws IOException {
25: buff.write(b);
26: }
27:
28: @Override
29: public void close() throws IOException {
30: this .flush();
31: }
32:
33: @Override
34: public void flush() throws IOException {
35: buff.flush();
36: byte[] newArray = new byte[part.data.length + buff.size()];
37: System.arraycopy(part.data, 0, newArray, 0, part.data.length);
38: byte[] buffArr = buff.toByteArray();
39: System.arraycopy(buffArr, 0, newArray, part.data.length,
40: buffArr.length);
41: }
42:
43: @Override
44: public void write(byte[] b, int off, int len) throws IOException {
45: buff.write(b, off, len);
46: }
47:
48: @Override
49: public void write(byte[] b) throws IOException {
50: buff.write(b);
51: }
52: }
|