Created
September 29, 2015 10:21
-
-
Save hacksoldier/b4690e6778b1014e513b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public byte[] getByteFromFile(File file) throws IOException, FileTooBigException { | |
| if (file.length() > MAX_FILE_SIZE) { | |
| throw new FileTooBigException(file); | |
| } | |
| ByteArrayOutputStream ous = null; | |
| InputStream ios = null; | |
| try { | |
| byte[] buffer = new byte[4096]; | |
| ous = new ByteArrayOutputStream(); | |
| ios = new FileInputStream(file); | |
| int read = 0; | |
| while ((read = ios.read(buffer)) != -1) { | |
| ous.write(buffer, 0, read); | |
| } | |
| }finally { | |
| try { | |
| if (ous != null) | |
| ous.close(); | |
| } catch (IOException e) { | |
| } | |
| try { | |
| if (ios != null) | |
| ios.close(); | |
| } catch (IOException e) { | |
| } | |
| } | |
| return ous.toByteArray(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment