Source code: org/activemq/util/FastInputStream.java
1 /**
2 *
3 * Copyright 2004 Hiram Chirino
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.activemq.util;
19
20 import java.io.ByteArrayInputStream;
21 import java.io.FilterInputStream;
22 import java.io.InputStream;
23 import java.lang.reflect.Constructor;
24
25 /**
26 * This provides InputStream that delegates to com.sleepycat.util.FastInputStream
27 * if it is available and if it is not it delegates to java.io.ByteArrayInputStream.
28 *
29 * This class allows ActiveMQ to not be dependent on the bdb lib. It might
30 * be worth it to just fully implement a FastInputStream ourselfs. I think
31 * it's just a ByteArrayInputStream what is not thread safe.
32 *
33 * @version $Revision: 1.1.1.1 $
34 */
35 public class FastInputStream extends FilterInputStream {
36
37 public FastInputStream(byte data[]) {
38 super(createInputStream(data));
39 }
40
41 /**
42 * @return
43 */
44 private static InputStream createInputStream(byte data[]) {
45 try {
46 Class c = FastInputStream.class.getClassLoader().loadClass("com.sleepycat.util.FastInputStream");
47 Constructor constructor = c.getConstructor(new Class[]{byte[].class});
48 return (InputStream)constructor.newInstance(new Object[]{data});
49 } catch (Throwable e) {
50 return new ByteArrayInputStream(data);
51 }
52 }
53
54 }