]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/clipboard/streams/AddBitmapHeaderInputStream.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / gfx / clipboard / streams / AddBitmapHeaderInputStream.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.utils.ui.gfx.clipboard.streams;
13
14 import java.io.IOException;
15 import java.io.InputStream;
16
17 import org.simantics.utils.ui.gfx.clipboard.headers.BitmapFileHeader;
18
19
20 /**
21  * Adds WIN32 API BITMAPFILEHEADER into the beginning of stream 
22  * 
23  * @author Marko Luukkainen
24  *
25  */
26 public class AddBitmapHeaderInputStream extends InputStream{
27     private InputStream iStream;
28     private int readBytes = 0;
29     private byte[] header;
30     
31     public AddBitmapHeaderInputStream(InputStream iStream) {
32         this.iStream = iStream;
33         BitmapFileHeader bfHeader = new BitmapFileHeader();
34         header = bfHeader.getBytes();
35     }
36     
37     @Override
38     public int read() throws IOException {
39         if (readBytes < header.length) {
40             return 0xff & header[readBytes++];
41         }
42         return iStream.read();
43     }
44 }