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