protected byte[] fileToByteArray(File file) throws IOException
   {
      FileInputStream in = null;

      try
      {
         if (channel == null || !channel.isOpen())
         {
            in = PrivilegedFileHelper.fileInputStream(file);
            channel = in.getChannel();
         }

         ByteBuffer bb = ByteBuffer.allocate((int)channel.size());
         channel.read(bb);
         if (bb.hasArray())
         {
            return bb.array();
         }
         else
         {
            // impossible code in most cases, as we use heap backed buffer
            byte[] tmpb = new byte[bb.capacity()];
            bb.get(tmpb);
            return tmpb;
         }
      }
      finally
      {
         if (in != null)
         {
            in.close();
            if (channel != null)
            {
               channel.close();
            }
         }
      }
   }
protected byte [ ] fileToByteArray ( File file ) throws IOException { FileInputStream in = null ; try { if ( channel == null || ! channel . isOpen ( ) ) { in = PrivilegedFileHelper . fileInputStream ( file ) ; channel = in . getChannel ( ) ; } ByteBuffer bb = ByteBuffer . allocate ( ( int ) channel . size ( ) ) ; channel . read ( bb ) ; if ( bb . hasArray ( ) ) { return bb . array ( ) ; } else { byte [ ] tmpb = new byte [ bb . capacity ( ) ] ; bb . get ( tmpb ) ; return tmpb ; } } finally { if ( in != null ) { in . close ( ) ; if ( channel != null ) { channel . close ( ) ; } } } }
Convert File to byte array. <br>
WARNING: Potential lack of memory due to call getAsByteArray() on stream data.

@return byte[] bytes array