Java Code Examples for java.io.BufferedInputStream

The following code examples are extracted from open source projects. You can click to vote up the examples you like. Your votes will be used in an intelligent system to get more and better code examples. Thanks for your votes!

Code Example 1:

  10 
vote

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/generic/.

Source UniversalLoader.java

byte[] bytearrayfromfile(File f) throws IOException {
  int filesize=(int)f.length();
  byte[] buffer=new byte[filesize];
  BufferedInputStream instream=new BufferedInputStream(new FileInputStream(f));
  for (int i=0; i < filesize; i++) {
    buffer[i]=(byte)instream.read();
    if (i % 1024 == 0)     System.out.print(".");
  }
  return buffer;
}
 

Code Example 2:

  9 
vote

From project accumulo, under directory /core/src/main/java/org/apache/accumulo/core/file/rfile/bcfile/.

Source Compression.java

@Override public synchronized InputStream createDecompressionStream(InputStream downStream,Decompressor decompressor,int downStreamBufferSize) throws IOException {
  if (downStreamBufferSize > 0) {
    codec.getConf().setInt("io.file.buffer.size",downStreamBufferSize);
  }
  CompressionInputStream cis=codec.createInputStream(downStream,decompressor);
  BufferedInputStream bis2=new BufferedInputStream(cis,DATA_IBUF_SIZE);
  return bis2;
}
 

Code Example 3:

  8 
vote

From project 360-Engine-for-Android, under directory /src/com/vodafone360/people/service/transport/tcp/.

Source TcpConnectionThread.java

/** 
 * Attempts to reconnect the socket if it has been closed for some reason.
 * @throws IOException Thrown if something goes wrong while reconnecting thesocket.
 */
private void reconnectSocket() throws IOException {
  HttpConnectionThread.logI("TcpConnectionThread.reconnectSocket()","Reconnecting Socket on " + mRpgTcpUrl + ":"+ mRpgTcpPort);
  mSocket=null;
  mSocket=new Socket();
  mSocket.connect(new InetSocketAddress(mRpgTcpUrl,mRpgTcpPort),TCP_DEFAULT_TIMEOUT);
  mBufferedInputStream=new BufferedInputStream(mSocket.getInputStream());
  mOs=mSocket.getOutputStream();
  HttpConnectionThread.logI("TcpConnectionThread.reconnectSocket()","Socket started: " + mRpgTcpUrl + ":"+ mRpgTcpPort);
}
 

Code Example 4:

  8 
vote

From project accumulo, under directory /core/src/main/java/org/apache/accumulo/core/file/rfile/bcfile/.

Source Compression.java

@Override public synchronized InputStream createDecompressionStream(InputStream downStream,Decompressor decompressor,int downStreamBufferSize) throws IOException {
  if (!isSupported()) {
    throw new IOException("SNAPPY codec class not specified. Did you forget to set property " + CONF_SNAPPY_CLASS + "?");
  }
  if (downStreamBufferSize > 0) {
    conf.setInt("io.file.buffer.size",downStreamBufferSize);
  }
  CompressionInputStream cis=snappyCodec.createInputStream(downStream,decompressor);
  BufferedInputStream bis2=new BufferedInputStream(cis,DATA_IBUF_SIZE);
  return bis2;
}
 

Code Example 5:

  7 
vote

From project acceleo, under directory /tests/org.eclipse.acceleo.common.tests/src/org/eclipse/acceleo/common/tests/unit/utils/modelutils/.

Source LoadFromInputStreamTest.java

/** 
 * Tests  {@link ModelUtils#load(InputStream,String,ResourceSet)} with valid inputStream and resourceSet.As the filename given is invalid, expects the model to be loaded as an XMI file.
 * @throws IOException Allows us not to catch it. Test just fails if thrown.
 */
public void testLoadModelFromValidInputInvalidExtension() throws IOException {
  for (  File model : models) {
    try {
      for (      String invalidFileName : INVALID_FILENAMES) {
        final FileInputStream fsInput=new FileInputStream(model);
        final BufferedInputStream buffInput=new BufferedInputStream(fsInput);
        final ResourceSet resourceSet=new ResourceSetImpl();
        final EObject result=ModelUtils.load(buffInput,invalidFileName,resourceSet);
        assertNotNull("ModelUtils didn't load its target model.",result);
        assertEquals("Loaded object was associated to an unexpected resourceSet.",resourceSet,result.eResource().getResourceSet());
        assertTrue("Model loaded as an unexpected type of resource.",result.eResource() instanceof XMIResource);
        buffInput.close();
        fsInput.close();
      }
    }
 catch (    FileNotFoundException e) {
      fail(MESSAGE_FILENOTFOUNDEXCEPTION_UNEXPECTED);
    }
  }
}
 

Code Example 6:

  7 
vote

From project acceleo, under directory /tests/org.eclipse.acceleo.common.tests/src/org/eclipse/acceleo/common/tests/unit/utils/modelutils/.

Source LoadFromInputStreamTest.java

/** 
 * Tests  {@link ModelUtils#load(InputStream,String,ResourceSet)} with a valid InputStream and<code>null</code> as a resourceSet. Expects a  {@link NullPointerException} to be thrown no matter whatthe filename is.
 * @throws IOException Allows us not to catch it. Test just fails if thrown.
 */
public void testLoadModelFromValidInputNullResourceSet() throws IOException {
  for (  File model : models) {
    FileInputStream fsInput=null;
    BufferedInputStream buffInput=null;
    try {
      fsInput=new FileInputStream(model);
      buffInput=new BufferedInputStream(fsInput);
      for (      String invalidFileName : INVALID_FILENAMES) {
        try {
          ModelUtils.load(buffInput,invalidFileName,null);
          fail(MESSAGE_NULLPOINTER_EXPECTED);
        }
 catch (        NullPointerException e) {
        }
      }
      try {
        ModelUtils.load(buffInput,model.getName(),null);
        fail(MESSAGE_NULLPOINTER_EXPECTED);
      }
 catch (      NullPointerException e) {
      }
    }
 catch (    FileNotFoundException e) {
      fail(MESSAGE_FILENOTFOUNDEXCEPTION_UNEXPECTED);
    }
 finally {
      if (buffInput != null && fsInput != null) {
        buffInput.close();
        fsInput.close();
      }
    }
  }
}
 

Code Example 7:

  7 
vote

From project acceleo, under directory /tests/org.eclipse.acceleo.common.tests/src/org/eclipse/acceleo/common/tests/unit/utils/modelutils/.

Source LoadFromInputStreamTest.java

/** 
 * Tests  {@link ModelUtils#load(InputStream,String,ResourceSet)} with valid inputStream and resourceSet.As the filename given is valid, expects the model to be loaded in an appropriate resource.
 * @throws IOException Allows us not to catch it. Test just fails if thrown.
 */
public void testLoadModelFromValidInputValidExtension() throws IOException {
  for (  File model : models) {
    try {
      final FileInputStream fsInput=new FileInputStream(model);
      final BufferedInputStream buffInput=new BufferedInputStream(fsInput);
      final ResourceSet resourceSet=new ResourceSetImpl();
      final EObject result=ModelUtils.load(buffInput,model.getName(),resourceSet);
      assertNotNull("ModelUtils didn't load its target model.",result);
      assertEquals("Loaded object was associated to an unexpected resourceSet.",resourceSet,result.eResource().getResourceSet());
      buffInput.close();
      fsInput.close();
    }
 catch (    FileNotFoundException e) {
      fail(MESSAGE_FILENOTFOUNDEXCEPTION_UNEXPECTED);
    }
  }
}
 

Code Example 8:

  7 
vote

From project accumulo, under directory /core/src/main/java/org/apache/accumulo/core/file/rfile/bcfile/.

Source Compression.java

@Override public synchronized InputStream createDecompressionStream(InputStream downStream,Decompressor decompressor,int downStreamBufferSize) throws IOException {
  if (!isSupported()) {
    throw new IOException("LZO codec class not specified. Did you forget to set property " + CONF_LZO_CLASS + "?");
  }
  InputStream bis1=null;
  if (downStreamBufferSize > 0) {
    bis1=new BufferedInputStream(downStream,downStreamBufferSize);
  }
 else {
    bis1=downStream;
  }
  conf.setInt("io.compression.codec.lzo.buffersize",64 * 1024);
  CompressionInputStream cis=codec.createInputStream(bis1,decompressor);
  BufferedInputStream bis2=new BufferedInputStream(cis,DATA_IBUF_SIZE);
  return bis2;
}
 

Code Example 9:

  7 
vote

From project accumulo, under directory /core/src/main/java/org/apache/accumulo/core/util/.

Source TTimeoutTransport.java

public static TTransport create(SocketAddress addr,long timeoutMillis) throws IOException {
  Socket socket=SelectorProvider.provider().openSocketChannel().socket();
  socket.setSoLinger(false,0);
  socket.setTcpNoDelay(true);
  socket.connect(addr);
  InputStream input=new BufferedInputStream(new SocketInputStream(socket,timeoutMillis),1024 * 10);
  OutputStream output=new BufferedOutputStream(new SocketOutputStream(socket,timeoutMillis),1024 * 10);
  return new TIOStreamTransport(input,output);
}
 

Code Example 10:

  7 
vote

From project activemq, under directory /activemq-core/src/main/java/org/apache/activemq/util/.

Source FactoryFinder.java

static public Properties loadProperties(String uri) throws IOException {
  ClassLoader classLoader=Thread.currentThread().getContextClassLoader();
  if (classLoader == null) {
    classLoader=StandaloneObjectFactory.class.getClassLoader();
  }
  InputStream in=classLoader.getResourceAsStream(uri);
  if (in == null) {
    in=FactoryFinder.class.getClassLoader().getResourceAsStream(uri);
    if (in == null) {
      throw new IOException("Could not find factory class for resource: " + uri);
    }
  }
  BufferedInputStream reader=null;
  try {
    reader=new BufferedInputStream(in);
    Properties properties=new Properties();
    properties.load(reader);
    return properties;
  }
  finally {
    try {
      reader.close();
    }
 catch (    Exception e) {
    }
  }
}
 

Code Example 11:

  6 
vote

From project 360-Engine-for-Android, under directory /tests/src/com/vodafone360/people/tests/service/transport/tcp/conn_less/respreader/.

Source ResponseReaderThreadTest.java

@Suppress @MediumTest public void testStartConnection(){
  DecoderThread decoder=new DecoderThread();
  MockTcpConnectionThread mockThread=new MockTcpConnectionThread(decoder,null);
  MockResponseReaderThread respReader=new MockResponseReaderThread(mockThread,decoder,null);
  MockOTAInputStream mIs=new MockOTAInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5}));
  respReader.setInputStream(new BufferedInputStream(mIs));
  assertNull(respReader.getConnectionThread());
  respReader.startConnection();
  try {
    Thread.sleep(1000);
  }
 catch (  InterruptedException e) {
  }
  assertNotNull(respReader.getConnectionThread());
  if (null != respReader.getConnectionThread()) {
    assertTrue(respReader.getConnectionThread().isAlive());
  }
  assertTrue(respReader.getIsConnectionRunning());
}
 

Code Example 12:

  6 
vote

From project 360-Engine-for-Android, under directory /tests/src/com/vodafone360/people/tests/service/transport/tcp/conn_less/respreader/.

Source ResponseReaderThreadTest.java

@Suppress @MediumTest public void testStopConnection(){
  DecoderThread decoder=new DecoderThread();
  MockTcpConnectionThread mockThread=new MockTcpConnectionThread(decoder,null);
  MockResponseReaderThread respReader=new MockResponseReaderThread(mockThread,decoder,null);
  MockOTAInputStream mIs=new MockOTAInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5}));
  respReader.setInputStream(new BufferedInputStream(mIs));
  respReader.startConnection();
  try {
    Thread.sleep(1000);
  }
 catch (  InterruptedException e) {
  }
  Thread t=respReader.getConnectionThread();
  assertNotNull(t);
  if (null != t) {
    assertTrue(t.isAlive());
    assertTrue(respReader.getIsConnectionRunning());
  }
  respReader.stopConnection();
  try {
    Thread.sleep(1000);
  }
 catch (  InterruptedException e) {
  }
  assertNull(respReader.getInputStream());
  assertNull(respReader.getConnectionThread());
  assertFalse(respReader.getIsConnectionRunning());
}
 

Code Example 13:

  6 
vote

From project 360-Engine-for-Android, under directory /tests/src/com/vodafone360/people/tests/service/transport/tcp/conn_less/respreader/.

Source ResponseReaderThreadTest.java

@MediumTest public void testSetInputstream(){
  DecoderThread decoder=new DecoderThread();
  MockTcpConnectionThread mockThread=new MockTcpConnectionThread(decoder,null);
  MockResponseReaderThread respReader=new MockResponseReaderThread(mockThread,decoder,null);
  ByteArrayInputStream bais=new ByteArrayInputStream(new byte[]{1,2,3,4,5});
  respReader.setInputStream(new BufferedInputStream(bais));
  DataInputStream dis=(DataInputStream)respReader.getInputStream();
  assertNotNull(dis);
  if (null != dis) {
    boolean areBytesCorrect=true;
    for (int i=1; i < 6; i++) {
      try {
        int j=dis.readByte();
        if (-1 == j) {
          fail("Unexpected end of the DataInputStream");
          areBytesCorrect=false;
        }
 else         if (i != j) {
          fail("Characters differ: i: " + i + " vs. j: "+ j);
          areBytesCorrect=false;
        }
      }
 catch (      IOException e) {
      }
    }
    assertTrue(areBytesCorrect);
  }
  respReader.setInputStream(null);
  assertNull(respReader.getInputStream());
}
 

Code Example 14:

  6 
vote

From project 360-Engine-for-Android, under directory /tests/src/com/vodafone360/people/tests/service/transport/tcp/conn_less/respreader/.

Source ResponseReaderThreadTest.java

/** 
 * Test DecoderThread.getResponse() call.
 */
@Suppress @MediumTest public void testReadNextResponse(){
  MockDecoderThread decoder=new MockDecoderThread();
  MockTcpConnectionThread mockThread=new MockTcpConnectionThread(decoder,null);
  MockResponseReaderThread respReader=new MockResponseReaderThread(mockThread,decoder,null);
  byte[] payload=new byte[]{((byte)0xFF),((byte)0xFF),0x04,0,0,0,1,0,0,0,0,0,0,0,5,0,1,2,3,4,5};
  ByteArrayInputStream bais=new ByteArrayInputStream(payload);
  respReader.setInputStream(new BufferedInputStream(bais));
  respReader.startConnection();
  try {
    Thread.sleep(2000);
  }
 catch (  InterruptedException ie) {
  }
  assertNotNull("The decoder response should not have been NULL",decoder.getResponse());
  assertTrue("Incorrect payload",Arrays.equals(payload,decoder.getResponse()));
  respReader.stopConnection();
  payload=null;
  respReader=null;
  mockThread=null;
  decoder=null;
  bais=null;
  decoder=new MockDecoderThread();
  mockThread=new MockTcpConnectionThread(decoder,null);
  respReader=new MockResponseReaderThread(mockThread,decoder,null);
  payload=new byte[]{1,((byte)0xFF)};
  respReader.startConnection();
  try {
    Thread.sleep(2000);
  }
 catch (  InterruptedException ie) {
  }
  assertNull(decoder.getResponse());
  respReader.stopConnection();
  payload=null;
  respReader=null;
  mockThread=null;
  decoder=null;
  bais=null;
}
 

Code Example 15:

  6 
vote

From project acceleo, under directory /plugins/org.eclipse.acceleo.common/src/org/eclipse/acceleo/common/internal/utils/workspace/.

Source AcceleoWorkspaceUtil.java

/** 
 * This will try and load a ResourceBundle for the given qualified name.
 * @param qualifiedName Name if the resource bundle we need to load.
 * @return The loaded resource bundle.
 */
public synchronized ResourceBundle getResourceBundle(String qualifiedName){
  MissingResourceException originalException=null;
  try {
    ResourceBundle bundle=ResourceBundle.getBundle(qualifiedName);
    return bundle;
  }
 catch (  MissingResourceException e) {
    originalException=e;
  }
  if (changedContributions.size() > 0) {
    refreshContributions();
  }
  for (  Map.Entry<IPluginModelBase,Bundle> entry : workspaceInstalledBundles.entrySet()) {
    final Bundle bundle=entry.getValue();
    URL propertiesResource=bundle.getResource(qualifiedName.replace('.','/') + ".properties");
    if (propertiesResource != null) {
      InputStream stream=null;
      try {
        stream=propertiesResource.openStream();
        stream=new BufferedInputStream(stream);
        return new PropertyResourceBundle(stream);
      }
 catch (      IOException e) {
      }
 finally {
        try {
          if (stream != null) {
            stream.close();
          }
        }
 catch (        IOException e) {
        }
      }
    }
  }
  throw originalException;
}
 

Code Example 16:

  6 
vote

From project activemq, under directory /activemq-core/src/main/java/org/apache/activemq/command/.

Source ActiveMQStreamMessage.java

private void initializeReading() throws MessageNotReadableException {
  checkWriteOnlyBody();
  if (this.dataIn == null) {
    ByteSequence data=getContent();
    if (data == null) {
      data=new ByteSequence(new byte[]{},0,0);
    }
    InputStream is=new ByteArrayInputStream(data);
    if (isCompressed()) {
      is=new InflaterInputStream(is);
      is=new BufferedInputStream(is);
    }
    this.dataIn=new DataInputStream(is);
  }
}
 

Code Example 17:

  5 
vote

From project 360-Engine-for-Android, under directory /src/com/vodafone360/people/service/transport/tcp/.

Source ResponseReaderThread.java

/** 
 * Sets the input stream that will be used to read responses from.
 * @param inputStream The input stream to read from. Should not be null asthis would trigger a reconnect of the whole socket and cause all transport-threads to be restarted.
 */
public void setInputStream(BufferedInputStream inputStream){
  HttpConnectionThread.logI("RpgTcpResponseReader.setInputStream()","Setting new IS: " + ((null != inputStream) ? "not null" : "null"));
  if (null != inputStream) {
    mIs=new DataInputStream(inputStream);
  }
 else {
    mIs=null;
  }
}
 

Code Example 18:

  5 
vote

From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/generic/.

Source FileUtils.java

public static void unJar(String path,String to,boolean verbose){
  File file=new File(path);
  Utils.console("Starting unjar of: " + file.getAbsolutePath() + File.separator+ "*.jar");
  if (file.exists()) {
    File[] files;
    if (file.isFile()) {
      files=new File[]{file};
    }
 else {
      files=file.listFiles();
    }
    for (int i=0; i < files.length; i++) {
      if (!files[i].isDirectory() && files[i].getName().endsWith("jar")) {
        Utils.console("unJar file: " + files[i].getName() + " ("+ (i + 1)+ "/"+ files.length+ ")");
        try {
          FileInputStream fis=new FileInputStream(files[i]);
          JarInputStream zis=new JarInputStream(new BufferedInputStream(fis));
          ZipEntry entry;
          while ((entry=zis.getNextEntry()) != null) {
            writejarEntry(zis,entry,to,false);
          }
          zis.close();
        }
 catch (        IOException e) {
          Utils.log("unJar error:",e);
        }
      }
    }
  }
 else {
    System.err.println("Failed to create: " + file.getAbsolutePath());
  }
}
 

Code Example 19:

  5 
vote

From project aboutsip, under directory /modules/yajpcap/src/main/java/com/aboutsip/yajpcap/framer/layer1/.

Source PcapFramer.java

/** 
 * Frame the pcap frame. This frame is the entry into the pcap and we will always frame a pcap one before asking it to frame the rest
 * @param byteOrder
 * @param in
 * @return the framed PcapFrame or null if nothing left to frame in thestream
 * @throws IOException
 */
public PcapFrame frame(final ByteOrder byteOrder,final BufferedInputStream in) throws IOException {
  final int l=in.available();
  if (l == -1) {
    return null;
  }
  if (l < 16) {
    return null;
  }
  final byte[] record=new byte[16];
  in.read(record);
  return null;
}
 

Code Example 20:

  5 
vote

From project acceleo, under directory /plugins/org.eclipse.acceleo.common/src/org/eclipse/acceleo/common/internal/utils/workspace/.

Source AcceleoModelManager.java

/** 
 * Reads the state of the project.
 * @param project The given project
 * @return The state of the project
 */
private AcceleoProjectState readBuiltState(IProject project){
  File file=this.getSerializationFile(project);
  if (file != null && file.exists()) {
    try {
      DataInputStream in=new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
      try {
        String pluginID=in.readUTF();
        if (!pluginID.equals(AcceleoCommonPlugin.PLUGIN_ID)) {
          AcceleoCommonPlugin.log(AcceleoCommonMessages.getString("AcceleoModelManager.WrongFileFormat"),true);
        }
        String kind=in.readUTF();
        if (!"STATE".equals(kind)) {
          AcceleoCommonPlugin.log(AcceleoCommonMessages.getString("AcceleoModelManager.WrongFileFormat"),true);
        }
        if (in.readBoolean()) {
          return AcceleoModelManager.readState(project,in);
        }
      }
  finally {
        in.close();
      }
    }
 catch (    Exception e) {
      AcceleoCommonPlugin.log(e,true);
    }
  }
  return null;
}