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);
}
}
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);
}
}
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;
}
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());
}
}
}
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);
}
Aggregations