Android Open Source - thesearchbattle Stream Extensions






From Project

Back to project page thesearchbattle.

License

The source code is released under:

Apache License

If you think the Android project thesearchbattle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.raycoarana.thesearchbattle.io;
//  w  w w . j a  va2  s .  com
import android.util.Log;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class StreamExtensions {

    private static final String TAG = StreamExtensions.class.getSimpleName();

  public void copy(InputStream inputStream, OutputStream outputStream) {
    try {
      copyContents(inputStream, outputStream);
    } catch (IOException ex) {
      throw new RuntimeException("Can't copy database from assets", ex);
    } finally {
      safeClose(outputStream, inputStream);
    }
  }

  private void copyContents(InputStream inputStream, OutputStream outputStream) throws IOException {
    int SIXTEEN_KB = 16384;
    byte[] buffer = new byte[SIXTEEN_KB];
    int readCount;
    while((readCount = inputStream.read(buffer)) > 0) {
      outputStream.write(buffer, 0, readCount);
    }
  }

  public void safeClose(Closeable... closeables) {
    for(Closeable closeable : closeables) {
      tryToClose(closeable);
    }
  }

  private void tryToClose(Closeable closeable) {
    try {
      if (closeable != null) {
        closeable.close();
      }
    } catch (IOException ex) {
      Log.e(TAG, "Can't close the Closeable object", ex);
    }
  }

}




Java Source Code List

com.raycoarana.thesearchbattle.ApplicationTest.java
com.raycoarana.thesearchbattle.BattleArenaActivity.java
com.raycoarana.thesearchbattle.database.Database.java
com.raycoarana.thesearchbattle.io.ResultsRegister.java
com.raycoarana.thesearchbattle.io.StreamExtensions.java
com.raycoarana.thesearchbattle.model.Car.java
com.raycoarana.thesearchbattle.model.DataSetDefinition.java
com.raycoarana.thesearchbattle.model.Timer.java
com.raycoarana.thesearchbattle.search.BaseSearchEngine.java
com.raycoarana.thesearchbattle.search.FTSSearch.java
com.raycoarana.thesearchbattle.search.MemorySearch.java
com.raycoarana.thesearchbattle.search.SearchEngine.java