1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.converter; |
19 |
|
|
20 |
|
import org.apache.camel.Converter; |
21 |
|
|
22 |
|
import java.io.*; |
23 |
|
import java.nio.ByteBuffer; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@Converter |
32 |
0 |
public class NIOConverter { |
33 |
|
|
34 |
|
@Converter |
35 |
|
public static byte[] toByteArray(ByteBuffer buffer) { |
36 |
0 |
return buffer.array(); |
37 |
|
} |
38 |
|
|
39 |
|
@Converter |
40 |
|
public static ByteBuffer toByteBuffer(byte[] data) { |
41 |
0 |
return ByteBuffer.wrap(data); |
42 |
|
} |
43 |
|
|
44 |
|
@Converter |
45 |
|
public static ByteBuffer toByteBuffer(String value) { |
46 |
1 |
ByteBuffer buf = ByteBuffer.allocate(value.length()); |
47 |
1 |
byte[] bytes = value.getBytes(); |
48 |
1 |
buf.put(bytes); |
49 |
1 |
return buf; |
50 |
|
} |
51 |
|
@Converter |
52 |
|
public static ByteBuffer toByteBuffer(Short value) { |
53 |
0 |
ByteBuffer buf = ByteBuffer.allocate(2); |
54 |
0 |
buf.putShort(value); |
55 |
0 |
return buf; |
56 |
|
} |
57 |
|
@Converter |
58 |
|
public static ByteBuffer toByteBuffer(Integer value) { |
59 |
0 |
ByteBuffer buf = ByteBuffer.allocate(4); |
60 |
0 |
buf.putInt(value); |
61 |
0 |
return buf; |
62 |
|
} |
63 |
|
@Converter |
64 |
|
public static ByteBuffer toByteBuffer(Long value) { |
65 |
0 |
ByteBuffer buf = ByteBuffer.allocate(8); |
66 |
0 |
buf.putLong(value); |
67 |
0 |
return buf; |
68 |
|
} |
69 |
|
@Converter |
70 |
|
public static ByteBuffer toByteBuffer(Float value) { |
71 |
0 |
ByteBuffer buf = ByteBuffer.allocate(4); |
72 |
0 |
buf.putFloat(value); |
73 |
0 |
return buf; |
74 |
|
} |
75 |
|
@Converter |
76 |
|
public static ByteBuffer toByteBuffer(Double value) { |
77 |
0 |
ByteBuffer buf = ByteBuffer.allocate(8); |
78 |
0 |
buf.putDouble(value); |
79 |
0 |
return buf; |
80 |
|
} |
81 |
|
} |