private static final int RAW_DATA_BLOCK_SIZE = 16384 ;
public static final int ERROR_IO_EXCEPTION = 1 ;
public static final int ERROR_FILE_NOT_FOUND = 2 ;
public static byte [] LoadRaw (Context context, Uri uri, int Error){
InputStream inputStream = null ;
byte [] ret = new byte [0 ];
try {
inputStream = context.getContentResolver().openInputStream(uri);
if (inputStream!=null )
ret = InputStreamToByteArray(inputStream);
}
catch (FileNotFoundException e1) {
Error = ERROR_FILE_NOT_FOUND;
}
catch (IOException e) {
Error = ERROR_IO_EXCEPTION;
}
finally {
if (inputStream != null ) {
try {
inputStream.close();
}
catch (IOException e) {
Error = ERROR_IO_EXCEPTION;
}
}
}
return ret;
}
private static byte [] InputStreamToByteArray (InputStream inputStream) throws IOException{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte [] data = new byte [RAW_DATA_BLOCK_SIZE];
while ((nRead = inputStream.read(data, 0 , data.length)) != -1 ) {
buffer.write(data, 0 , nRead);
}
buffer.flush();
return buffer.toByteArray();
}