001 /** 002 * 003 * Copyright 2004 Hiram Chirino 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 package org.activemq.util; 019 020 import java.io.ByteArrayInputStream; 021 import java.io.FilterInputStream; 022 import java.io.InputStream; 023 import java.lang.reflect.Constructor; 024 025 /** 026 * This provides InputStream that delegates to com.sleepycat.util.FastInputStream 027 * if it is available and if it is not it delegates to java.io.ByteArrayInputStream. 028 * 029 * This class allows ActiveMQ to not be dependent on the bdb lib. It might 030 * be worth it to just fully implement a FastInputStream ourselfs. I think 031 * it's just a ByteArrayInputStream what is not thread safe. 032 * 033 * @version $Revision: 1.1.1.1 $ 034 */ 035 public class FastInputStream extends FilterInputStream { 036 037 public FastInputStream(byte data[]) { 038 super(createInputStream(data)); 039 } 040 041 /** 042 * @return 043 */ 044 private static InputStream createInputStream(byte data[]) { 045 try { 046 Class c = FastInputStream.class.getClassLoader().loadClass("com.sleepycat.util.FastInputStream"); 047 Constructor constructor = c.getConstructor(new Class[]{byte[].class}); 048 return (InputStream)constructor.newInstance(new Object[]{data}); 049 } catch (Throwable e) { 050 return new ByteArrayInputStream(data); 051 } 052 } 053 054 }