Search in sources :

Example 26 with BufferedInputStream

use of java.io.BufferedInputStream in project pinot by linkedin.

the class StarTreeSerDe method fromBytes.

/**
   * De-serializes a StarTree structure.
   */
public static StarTreeInterf fromBytes(InputStream inputStream) throws IOException, ClassNotFoundException {
    BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
    StarTreeFormatVersion version = getStarTreeVersion(bufferedInputStream);
    switch(version) {
        case ON_HEAP:
            return fromBytesToOnHeapFormat(bufferedInputStream);
        case OFF_HEAP:
            return fromBytesToOffHeapFormat(bufferedInputStream);
        default:
            throw new RuntimeException("StarTree version number not recognized: " + version);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream)

Example 27 with BufferedInputStream

use of java.io.BufferedInputStream in project pinot by linkedin.

the class StarTreeSerDe method fromFile.

/**
   *
   * @param starTreeFile  Star Tree index file
   * @param readMode Read mode MMAP or OFF-HEAP (direct memory), only applicable to StarTreeOffHeap.
   * @return
   */
public static StarTreeInterf fromFile(File starTreeFile, ReadMode readMode) throws IOException, ClassNotFoundException {
    InputStream inputStream = new FileInputStream(starTreeFile);
    BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
    StarTreeFormatVersion starTreeVersion = getStarTreeVersion(bufferedInputStream);
    if (starTreeVersion.equals(StarTreeFormatVersion.ON_HEAP)) {
        return fromBytesToOnHeapFormat(bufferedInputStream);
    } else if (starTreeVersion.equals(StarTreeFormatVersion.OFF_HEAP)) {
        return new StarTreeOffHeap(starTreeFile, readMode);
    } else {
        throw new RuntimeException("Unrecognized version for Star Tree " + starTreeVersion);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream)

Example 28 with BufferedInputStream

use of java.io.BufferedInputStream in project qksms by moezbhatti.

the class ContactHelper method getBitmap.

public static Bitmap getBitmap(Context context, long id) {
    Bitmap bitmap = null;
    try {
        Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(id));
        InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), contactUri, true);
        if (input == null) {
            return null;
        }
        BufferedInputStream buf = new BufferedInputStream(input);
        bitmap = BitmapFactory.decodeStream(buf);
        buf.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Uri(android.net.Uri)

Example 29 with BufferedInputStream

use of java.io.BufferedInputStream in project OpenAttestation by OpenAttestation.

the class TextConsoleTest method testMain1.

@Test
public void testMain1() {
    FileOutputStream fos = null;
    BufferedInputStream bis = null;
    try {
        fos = new FileOutputStream(file);
        System.setErr(new PrintStream(fos));
        TextConsole.main(args1);
        bis = new BufferedInputStream(new FileInputStream(new File(file.toString())));
        byte[] b = new byte[1024];
        int length = bis.read(b);
        String temp = new String(b, 0, length).trim();
        StringBuffer sb = new StringBuffer();
        sb.append("Unrecognized command:").append(" oat_os:").append(" com.intel.mtwilson.client.cmd.oat_os");
        Assert.assertEquals(sb.toString(), temp);
    } catch (IOException e) {
        System.out.println("error message " + e.toString());
    } catch (Exception e) {
        System.out.println("error message " + e.toString());
    } finally {
        try {
            fos.close();
            bis.close();
        } catch (IOException e) {
            System.out.println("error message " + e.toString());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 30 with BufferedInputStream

use of java.io.BufferedInputStream in project OpenGrok by OpenGrok.

the class TextAnalyzer method getReader.

protected Reader getReader(InputStream stream) throws IOException {
    InputStream in = stream.markSupported() ? stream : new BufferedInputStream(stream);
    String charset = null;
    in.mark(3);
    byte[] head = new byte[3];
    int br = in.read(head, 0, 3);
    if (br >= 2 && (head[0] == (byte) 0xFE && head[1] == (byte) 0xFF) || (head[0] == (byte) 0xFF && head[1] == (byte) 0xFE)) {
        charset = "UTF-16";
        in.reset();
    } else if (br >= 3 && head[0] == (byte) 0xEF && head[1] == (byte) 0xBB && head[2] == (byte) 0xBF) {
        // InputStreamReader does not properly discard BOM on UTF8 streams,
        // so don't reset the stream.
        charset = "UTF-8";
    }
    if (charset == null) {
        in.reset();
        charset = Charset.defaultCharset().name();
    }
    return new InputStreamReader(in, charset);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)3306 IOException (java.io.IOException)1660 FileInputStream (java.io.FileInputStream)1550 InputStream (java.io.InputStream)1473 File (java.io.File)886 BufferedOutputStream (java.io.BufferedOutputStream)499 FileOutputStream (java.io.FileOutputStream)467 ByteArrayInputStream (java.io.ByteArrayInputStream)330 URL (java.net.URL)298 FileNotFoundException (java.io.FileNotFoundException)273 DataInputStream (java.io.DataInputStream)263 OutputStream (java.io.OutputStream)253 ZipEntry (java.util.zip.ZipEntry)248 ByteArrayOutputStream (java.io.ByteArrayOutputStream)237 ArrayList (java.util.ArrayList)148 ZipInputStream (java.util.zip.ZipInputStream)143 GZIPInputStream (java.util.zip.GZIPInputStream)135 InputStreamReader (java.io.InputStreamReader)132 HttpURLConnection (java.net.HttpURLConnection)119 HashMap (java.util.HashMap)119