|
1 |
| package com.agical.rdoc.util; |
|
2 |
| |
|
3 |
| import java.io.IOException; |
|
4 |
| import java.io.InputStream; |
|
5 |
| |
|
6 |
| import com.agical.rdoc.core.converter.ConversionException; |
|
7 |
| import com.agical.rdoc.core.converter.InputStreamConverter; |
|
8 |
| |
|
9 |
| public class InputStreamToByteArrayConverter implements InputStreamConverter { |
|
10 |
| |
|
11 |
3
| public Object convert(InputStream inputStream) throws ConversionException {
|
|
12 |
3
| try {
|
|
13 |
3
| byte[] tmp = new byte[1024];
|
|
14 |
3
| byte[] result = new byte[0];
|
|
15 |
3
| int read = -1;
|
|
16 |
3
| int cursor = 0;
|
|
17 |
?
| while( (read = inputStream.read(tmp)) != -1 ) {
|
|
18 |
101
| byte[] tmp2 = new byte[cursor+read];
|
|
19 |
101
| System.arraycopy(result, 0, tmp2, 0, cursor);
|
|
20 |
101
| System.arraycopy(tmp, 0, tmp2, cursor, read);
|
|
21 |
101
| cursor += read;
|
|
22 |
101
| result = tmp2;
|
|
23 |
| } |
|
24 |
3
| return result;
|
|
25 |
| } catch (IOException e) { |
|
26 |
0
| throw new ConversionException( "Could not convert " + inputStream, e );
|
|
27 |
| } |
|
28 |
| } |
|
29 |
| |
|
30 |
| } |