1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.utils.ui.gfx.clipboard.streams;
14 import java.io.IOException;
15 import java.io.OutputStream;
17 import org.simantics.utils.ui.gfx.clipboard.headers.BitmapFileHeader;
21 * Removes WIN32 API BITMAPFILEHEADER from the beginning of stream
23 * @author Marko Luukkainen
26 public class RemoveBitmapHeaderOutputStream extends OutputStream{
27 private OutputStream oStream;
28 private int byteCount = 0;
30 public RemoveBitmapHeaderOutputStream(OutputStream oStream) {
31 this.oStream = oStream;
35 public void write(byte[] b) throws IOException {
36 if (byteCount >= BitmapFileHeader.sizeof) {
38 } else if (b.length >= BitmapFileHeader.sizeof - byteCount){
39 byte[] newArray = new byte[b.length - BitmapFileHeader.sizeof + byteCount];
40 System.arraycopy(b, BitmapFileHeader.sizeof - byteCount, newArray, 0, newArray.length);
41 byteCount = BitmapFileHeader.sizeof;
42 super.write(newArray);
50 public void write(byte[] b, int off, int len) throws IOException {
51 if (byteCount >= BitmapFileHeader.sizeof)
52 super.write(b, off, len);
54 throw new IOException("Operation not supported, cannot remove header");
58 public void write(int b) throws IOException {
59 if (byteCount >= BitmapFileHeader.sizeof) {