1 package emissary.core.channels;
2
3 import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
4 import org.apache.commons.lang3.Validate;
5
6 import java.nio.channels.SeekableByteChannel;
7
8
9
10
11 public final class InMemoryChannelFactory {
12 private InMemoryChannelFactory() {}
13
14
15
16
17
18
19
20 public static SeekableByteChannelFactory create(final byte[] bytes) {
21 return ImmutableChannelFactory.create(new InMemoryChannelFactoryImpl(bytes));
22 }
23
24
25
26
27 private static final class InMemoryChannelFactoryImpl implements SeekableByteChannelFactory {
28
29
30
31 private final byte[] bytes;
32
33 private InMemoryChannelFactoryImpl(final byte[] bytes) {
34 Validate.notNull(bytes, "Required: bytes not null");
35
36 this.bytes = bytes;
37 }
38
39
40
41
42
43
44
45 @Override
46 public SeekableByteChannel create() {
47 return new SeekableInMemoryByteChannel(bytes);
48 }
49 }
50 }