karbaev

Untitled

Oct 14th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public byte[] read(File file) throws IOException, FileTooBigException {
  2. if (file.length() > MAX_FILE_SIZE) {
  3. throw new FileTooBigException(file);
  4. }
  5. ByteArrayOutputStream ous = null;
  6. InputStream ios = null;
  7. try {
  8. byte[] buffer = new byte[4096];
  9. ous = new ByteArrayOutputStream();
  10. ios = new FileInputStream(file);
  11. int read = 0;
  12. while ((read = ios.read(buffer)) != -1) {
  13. ous.write(buffer, 0, read);
  14. }
  15. }finally {
  16. try {
  17. if (ous != null)
  18. ous.close();
  19. } catch (IOException e) {
  20. }
  21.  
  22. try {
  23. if (ios != null)
  24. ios.close();
  25. } catch (IOException e) {
  26. }
  27. }
  28. return ous.toByteArray();
  29. }
Add Comment
Please, Sign In to add comment