Re: Taking the Contents of a File object and converting it to a byte array



Roedy Green wrote:
On 30 Dec 2005 08:33:14 -0800, "MattC" <matthew.n.connors@xxxxxxxx>
wrote, quoted or indirectly quoted someone who said :


   /* Move the data in the File object to a byte array */
      InputStream in = new FileInputStream(templateFile);
      int length = new Long(templateFile.length()).intValue();

(I didn't see that...)

You don't need a ByteArrayOutputStream or a byte[1024] buffer.

Even if you did need a buffer, use a BufferedInputStream rather than
rolling your own.

You don't mean reading a byte at a time, do you? If nothing else, the synchronisation would kill performance, unless the JVM was something special.


Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.



Relevant Pages

  • [PATCH] Numerous fixes to kernel-doc info in source files.
    ... static inline int ffs ... @buffer: where the data must be copied. ... * struct kfifo with kfree. ... @timer: ...
    (Linux-Kernel)
  • [UNIX] Multiple Vulnerabilities in Citadel/UX
    ... could allow complete control over a vulnerable server. ... Citadel server as can be seen by this simplistic code snippet: ... configuration buffers, leading to the possibility of carrying out a buffer ... int connect_to_host; ...
    (Securiteam)
  • Re: pushing the envelope with sockets
    ... receiving on the socket they are received (upto the buffer size), you can even change what happens if the buffer runs full. ... int read = S.EndReceive; ... class AsyncReader: Reader ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH] Updated: Reworked Cell OProfile: SPU mutex lock fix
    ... arch-independent pieces of the OProfile kernel driver that this patch ... kernel driver patches. ... into the kernel buffer without holding the buffer_mutex lock. ... int spu_sync_start; ...
    (Linux-Kernel)
  • [PATCH] char: make functions static in synclinkmp.c
    ... int *eof, void *data) ... /* Allocate DMA buffers for the transmit and receive descriptor lists. ... * This buffer is used to pass an assembled frame to the line discipline. ...
    (Linux-Kernel)