1 5 package com.oreilly.servlet.multipart; 6 7 import java.io.OutputStream ; 8 import java.io.FilterOutputStream ; 9 import java.io.IOException ; 10 11 17 public class MacBinaryDecoderOutputStream extends FilterOutputStream { 18 private int bytesFiltered = 0; 19 private int dataForkLength = 0; 20 21 public MacBinaryDecoderOutputStream(OutputStream out) { 22 super(out); 23 } 24 25 public void write(int b) throws IOException { 26 if (bytesFiltered <= 86 && bytesFiltered >= 83) { 29 int leftShift = (86 - bytesFiltered) * 8; 30 dataForkLength = dataForkLength | (b & 0xff) << leftShift; 31 } 32 33 else if (bytesFiltered < (128 + dataForkLength) && bytesFiltered >= 128) { 35 out.write(b); 36 } 37 38 bytesFiltered++; 39 } 40 41 public void write(byte b[]) throws IOException { 42 write(b, 0, b.length); 43 } 44 45 public void write(byte b[], int off, int len) throws IOException { 46 if (bytesFiltered >= (128 + dataForkLength)) { 48 bytesFiltered += len; 49 } 50 else if (bytesFiltered >= 128 && 52 (bytesFiltered + len) <= (128 + dataForkLength)) { 53 out.write(b, off, len); 54 bytesFiltered += len; 55 } 56 else { 58 for (int i = 0 ; i < len ; i++) { 59 write(b[off + i]); 60 } 61 } 62 } 63 } 64 | Popular Tags |