Maximum size of a byte array?

Hi,
I'm trying to read in a file into a byte array as following:
byte[]inputformat = new byte[1280];
FileInputStream in= new FileInputStream(file);
BufferedInputStream buffer= new BufferedInputStream(in);
int len = buffer.read(inputformat);
The problem appears when I try to access the 1024th array-element (inputformat[1024]) afterwards. Is there a limitation in the byte-arrays, or prehaps in the buffer.read-method?
All comments are welcomed!
Cheers,
Slafs

I executed the following code:
import java.io.*;
public class BufferTest {
    public static void main(String[] args) {
        try {
            byte[] inputFormat = new byte[1280];
            File inFile = new File(args[0]);
            FileInputStream in = new FileInputStream(inFile);
            BufferedInputStream bis = new BufferedInputStream(in);
            int len = bis.read(inputFormat);
            System.out.println("Read " + len + " bytes");
        catch (IOException e) {
            System.out.println("Error: " + e.toString());
}To produce the following output:
$ java BufferTest snapshot1.png
Read 1280 bytesSo, I am not sure where your problem lies, but I don't think it's in the code you posted.
Good luck
Lee

Similar Messages

  • MD5 - Size Of Digested Byte Array

    Hey There.
    After MD5 digesting and then Base64Encoding a string, I would end up with a byte array such as this:
    GH70Q2Ei0cwvQNwrkvDroA==
    It changes with the input, but is always 24 characters in length. I would have thought it to be 32 characters. Any reasons???
    I'm doing the UTF-8 thing. Refer to code in previous post where I'm looking for critique of code.
    Thanks,
    Vic

    I do think about what I'm doing. I know I have to
    encode digested value to get data into db. I'm not
    aware of HEX encoding, only BASE64.If you aware of Base64 and MD5, I suppose you know the digest size produced by MD5 and the fact that Base64 increases the size of encoded data to fixed percentage (which is less then 50%).

  • Byte array size changes

    For some reason the size of my byte arrays change, and it is causing problems using an AES Cipher.
    The length of the byte array is 16 when I first encrypt text, but when I try and decrypt it, it tells me the length is 29. Then I have an IllegalBlockSizeException.
    Can someone explain how to overcome this problem?
    I used the UTF-8 encoding on Ubuntu 8.04

    TamalinJava wrote:
    For some reason the size of my byte arrays change, and it is causing problems using an AES Cipher.A byte[] has a fixed size, you cannot change it.
    The length of the byte array is 16 when I first encrypt text, but when I try and decrypt it, it tells me the length is 29. Then I have an IllegalBlockSizeException.
    I used the UTF-8 encoding on Ubuntu 8.04This is your problem. It translates values >= 128 to be two characters.
    Can someone explain how to overcome this problem?Don't try to write binary data as if it were text. (Write it as binary data)

  • Encrypt function in 10g - RAW maximum size issue

    Hello,
    I m trying to encrypt some data using the ENCRYPT function provided by Oracle 10g.
    It appears that the function uses only RAW type and RAW apparently has a maximum size of 2000 bytes.
    And in my situation, the RAW data I would get after encrypting would be well above 2000 bytes. Can some one throw some light on how I can work around this situation.
    I'd appreciate any help here.
    Thanks
    Nikhil

    Should I convert the 9i database?You can, but not mandatory.
    from WE8MSWIN1252 to UTF8?I strongly advise you to read the following metalink
    notes :
    * Changing WE8ISO8859P1/ WE8ISO8859P15 or
    WE8MSWIN1252 to (AL32)UTF8 with ALTER DATABASE
    CHARACTERSET - Note:260192.1
    * NLS considerations in Import/Export - Frequently
    Asked Questions - Note:227332.1
    Nicolas.Nicolas:
    These links were very helpful!
    I actually was not aware of the fact that CHAR and VARCHAR2 are, by default, defined in terms of bytes, not characters when declaring column size. It seems like all I have to do is alter my tables in the 10g environment to be NVARCHAR2 instead of VARCHAR2, and that will define the columns in characters, not bytes.

  • Generated Webservice proxy: Maximimum size of byte array

    Hi,
    We have generated a webservice proxy with JDeveloper (version 10.1.3.4.0) from a WSDL supplied by a .Net webservice. One of the Webservice returns a byte array. We are facing a problem when the size of the returned byte array exceeds the limit of 5 MB. We have tried to increase the heap size of the OC4J but that did not solve the problem.
    Does anyone know if there is a maximum value limit which can be passed through a byte array? Is it configurable?
    A workaround would be flushing the byte array in chunks, but the webservice returns the byte array as a single returned value.
    Regards,
    Sjoerd

    Hi,
    The webservice was called by Oracle Forms. The problem was solved by Metalink Note 562561.1 - Webservice Fails To Run With java.lang.OutOfMemoryError.
    Regards,
    Sjoerd

  • Maximum size of an array

    Hello,
    I'm using LabVIEW2009 under windows XP (4Go RAM).
    When I create a large array using the "Initilaize an array" fucntion (for example a 2D 512x512 array of U16), I've an error message "Insufficient memory" while this table weighs only 520kb if I try to use it (for example, save it to a binary file). My final need if a 2D 512x512 array of double precision.
    Is there a maximum size for array in LabVIEW? If yes, could we modify it?
    Thank you in advance,
    Eric

    That's very strange, you are correct the array is not that big.
    Is your code making a lot of copies of the array?
    Can you initialize the array on a fresh start:
    -Reboot your PC
    -Start LabVIEW
    -Create an empty VI
    -Place the initalization inside this VI
    Run code.
    One thing to advice, make one of your constants a control, this will prevent LabVIEW from doubling the memory upon editing the array in memory.*
    Ton
    *When you initialize an error with only constants LabVIEW will make the array a Constant in memory, when you edit the array, LabVIEW needs to declare a copy. This is very usefull for read-only (lookup) array.
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • How to read a large file(size around 100 kbytes) into a byte array in JAVA

    aa

    But I cannot use array subscript as a long value.what do you mean?
    are you rying the following:
    long aSize = 100000;
    byte[] array = new byte[aSize];
    if this is the case, then don't do it, for your 100k file int is far more than enough.
    but in case you jsut get error while:
    byte b = array[100000];
    then it's probably because you'r array is of size 100000, that means you have bytes from 0 to 99999 in there, and 100000 is one passed the end of the array.... jus in case make your array size to be 1234567 (far more than needed for your file) and see if you still get that exception, if not, then your array was too small. but if it fixes your prob, then don't leave it as it is, try to work out the right size for array and use that....
    i wouldn't recommend using static array size, since that file might some day be bigger than you expected, and then you'd have to recompile your program.
    HTH

  • Reducing size of Image or byte array

    Hello,
    I am making a program where i have to send user's screen to another PC,
    So I use class Robot to make a screen capture and send it via UDP.
    However this is still too slow, my question is: is there some library to compress the size of byte array or Image?
    Thanks for help,
    Juraj

    thanks for help i found it
    byte[] input = ...;
    // Create the compressor with highest level of compression
    Deflater compressor = new Deflater();
    compressor.setLevel(Deflater.BEST_COMPRESSION);
    // Give the compressor the data to compress
    compressor.setInput(input);
    compressor.finish();

  • StreamInsight Exception: The event is too big to fit into one page. The maximum event size is '230' bytes

    Hi,
    I'm using version 2.1 and getting the following exception
    System.InvalidOperationException: The event is too big to fit into one page. The maximum event size is '230' bytes, but the event size is '234' bytes. Try reduce the size of the event payload.
    Everywhere I read tells me the maximum page size is 16K, so why am I hitting a 230 byte limit? Secondly how can I increase this to the full 16K?
    Thanks,
    Jeremy

    That is ... unusual. I've never seen that. Can you provide some details on what your payload looks like and the query?
    DevBiker (aka J Sawyer)
    Microsoft MVP - Sql Server (StreamInsight)
    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

  • Error:  Debug Component exceeds maximum size (65535 bytes)

    Hi All,
    It would seem that I have come across a limitation in the CAP file format for Java Card 2.2.1. When I run the Sun 2.2.1 converter I get the following output:
    Converting oncard package
    Java Card 2.2.1 Class File Converter, Version 1.3
    Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
    error:  Debug Component exceeds maximum size (65535 bytes).
    Cap file generation failed.
    conversion completed with 1 errors and 0 warnings.This also happens with JCDK 2.2.2. Is there any way around this limitation? I can instruct the compiler to not generate some of the debug output such as variable attributes, but this makes the debugger less than useful. I could not find anything in the JCVM spec for JC2.2.1 that mentions this limitation (I could have missed it very easily if it is there). Is this a limitation that will be lifted in new versions of the standard? This is tarting to be a bit of a problem as our code base has outgrown our development tools (no more debugger). Compiling and running without debug information works fine.
    Any information on this would be much appreciated.
    Cheers,
    Shane

    For those that are interested, I found this in the Java Card VM spec. u1 and u2 are 1 and 2 byte unsigned values respectively. It would appear that it is a limitation of the CAP file format. We have managed to work around this problem (parsing the debug component of the cap file was very informative) by shortening package names, reducing exception handling, and removing classes that we could do without.
    It looks like this is removed for JC3.0 Connected Edition does not have this issue as it does not have CAP files, but JC2.2.2 and JC3.0 Classic Edition have this same issue. It would be nice if there was a converter/debugger combination that removed this limitation. If anyone knows of such a combination, I am all ears! I know for a fact that JCOP does not :(
    Cheers,
    Shane
    *6.14 Debug Component*
    This section specifies the format for the Debug Component. The Debug Component contains all the metadata necessary for debugging a package on a suitably instrumented Java Card virtual machine. It is not required for executing Java Card programs in a non-debug environment.
    The Debug Component references the Class Component (Section 6.8 "Class Component”), Method Component (Section 6.9 "Method Component”), and Static Field Component (Section 6.10 "Static Field Component”). No components reference the Debug Component.
    The Debug Component is represented by the following structure:
    {code}
    debug_component {
    u1 tag
    u2 size
    u2 string_count
    utf8_info strings_table[string_count]
    u2 package_name_index
    u2 class_count
    class_debug_info classes[class_count]
    {code}
    The items in the debug_component structure are defined as follows:
    *tag* tag item has the value COMPONENT_Debug (12).
    *size* The number of bytes in the component, excluding the tag and size items. The value of size must be greater than zero.

  • Export buffer maximum size

    Hi,
    For the parameter buffer used in export what is the maximum size we can give as input.

    BUFFER
    Default: operating system-dependent. See your Oracle operating system-specific documentation to determine the default value for this parameter.
    Specifies the size, in bytes, of the buffer used to fetch rows. As a result, this parameter determines the maximum number of rows in an array fetched by Export. Use the following formula to calculate the buffer size:
    buffer_size = rows_in_array * maximum_row_size
    If you specify zero, the Export utility fetches only one row at a time.
    Tables with columns of type LOBs, LONG, BFILE, REF, ROWID, LOGICAL ROWID, or DATE are fetched one row at a time.
    Note:
    The BUFFER parameter applies only to conventional path Export. It has no effect on a direct path Export. For direct path Exports, use the RECORDLENGTH parameter to specify the size of the buffer that Export uses for writing to the export file.
    Example: Calculating Buffer Size
    This section shows an example of how to calculate buffer size.
    The following table is created:
    CREATE TABLE sample (name varchar(30), weight number);
    The maximum size of the name column is 30, plus 2 bytes for the indicator. The maximum size of the weight column is 22 (the size of the internal representation for Oracle numbers), plus 2 bytes for the indicator.
    Therefore, the maximum row size is 56 (30+2+22+2).
    To perform array operations for 100 rows, a buffer size of 5600 should be specified.
    Ref. Oracle® Database Utilities
    10g Release 2 (10.2)
    Part Number B14215-01
    Ch. 19 Original Export and Import
    ~ Madrid

  • How do I store an Int, a short, and multiple bytes from file in byte array

    I'm attempting to do this for a project but can't figure out how to store the three values in one byte array. This is what i've tried
    public void send(byte[] input)
              // TODO
              ByteArrayInputStream bais = new ByteArrayInputStream(input);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              DataOutputStream dos = new DataOutputStream(baos);
              byte[] pData = new byte[100];
              try {
                   dos.writeShort(checkSum);
                   dos.writeInt(nextSeqNum);
                   pData=baos.toByteArray();
                   bais.read(pData);
              } catch (IOException e) {
              DatagramPacket dgp = new DatagramPacket(pData, pData.length);When i set pData=baos.toByteArray() it changes the size and then stops me from being able to read the other 94 bytes into the array to send. Any ideas?

    You don't need the ByteArrayInputStream at all.
    dos.writeShort(checkSum);
    dos.writeInt(nextSeqNum);
    dos.write(input);
    pData = baos.toByteArray();
    When i set pData=baos.toByteArray() it changes the sizeNo, it makes it refer to a new byte[] array containing what you've written to the BAOS. That's what it's supposed to do.

  • How can i convert object to byte array very*100 fast?

    i need to transfer a object by datagram packet in embeded system.
    i make a code fallowing sequence.
    1) convert object to byte array ( i append object attribute to byte[] sequencailly )
    2) send the byte array by datagram packet ( by JNI )
    but, it's not satisfied my requirement.
    it must be finished in 1ms.
    but, converting is spending 2ms.
    network speed is not bottleneck. ( transfer time is 0.3ms and packet size is 4096 bytes )
    Using ObjectOutputStream is very slow, so i'm using this way.
    is there antoher way? or how can i improve?
    Edited by: JongpilKim on May 17, 2009 10:48 PM
    Edited by: JongpilKim on May 17, 2009 10:51 PM
    Edited by: JongpilKim on May 17, 2009 10:53 PM

    thanks a lot for your reply.
    now, i use udp socket for communication, but, i must use hardware pci communication later.
    so, i wrap the communication logic to use jni.
    for convert a object to byte array,
    i used ObjectInputStream before, but it was so slow.
    so, i change the implementation to use byte array directly, like ByteBuffer.
    ex)
    public class ByteArrayHelper {
    private byte[] buf = new byte[1024];
    int idx = 0;
    public void putInt(int val){
    buf[idx++] = (byte)(val & 0xff);
    buf[idx++] = (byte)((val>>8) & 0xff);
    buf[idx++] = (byte)((val>>16) & 0xff);
    buf[idx++] = (byte)((val>>24) & 0xff);
    public void putDouble(double val){ .... }
    public void putFloat(float val){ ... }
    public byte[] toByteArray(){ return this.buf; }
    public class PacketData {
    priavte int a;
    private int b;
    public byte[] getByteArray(){
    ByteArrayHelper helper = new ByteArrayHelper();
    helper.putInt(a);
    helper.putInt(b);
    return helper.toByteArray();
    but, it's not enough.
    is there another way to send a object data?
    in java language, i can't access memory directly.
    in c language, if i use struct, i can send struct data to copy memory by socket and it's very fast.
    Edited by: JongpilKim on May 18, 2009 5:26 PM

  • Is there a null value that I can put into a byte array?

    I have a byte[] that I'm trying to make smaller, at the moment, in order to do so, i'm writing it byte-by-byte to another byte[] called temp. Both are set to the same size, because I don't know exactly what the initial array will compress to.
    For example, my method will write a single byte that will tell the decompressor to carry out the next instruction 5 times (eg aaaaa = 5a), but after the instruction, I want to set the 4 a's afterwards to an empty value so that I can then iterate through temp, finding out how long to make the output byte[] by counting how many null's there are.
    Eclipse is telling me null is not possible to use, I was just wondering if there is an equivalent I can use?

    That's an idea!
    The only thing is then when I come to iterate through the byte array to write it to my output array, it throws up an error that I'm trying to compare a byte to a byte[]:
              int next = 0;
              byte[] n = new byte[0];
              for (int i = 0; i < temp.length; i++) {
                   if (temp[i] != n) {
                        output[next] = temp;
                        next++;
              return output;

  • Ideas on transforming a byte array?

    I'm writing a program to compress files - I read it in, transform it and then write it out again. I'm just having a little confusion with the transforming.
    I'm keeping it as basic as possible and just starting with finding and replacing repeating bytes with an instruction of how many times the following byte is repeated. ie a a a a a = 5 a _ _ _
    In order to do this I create a temporary array to write to (initialised to the same size as the input) and then check through for repetitions. If something is repeated more than twice (3+), then a marker byte is put in (I wanted to have specific ones for however many times the byte is repeated - within reason - which is the switch statement below), the next byte is the byte to be repeated and then I want to jump forward to the next different byte.
    I then go through the temp array count the repetitions, create a new smaller byte array and write temp[] to output[] ignoring the bytes that are repeated.
    This is what I have so far, but it doesn't quite do what I want:
    public class Transformer {
         byte[] input;
         byte[] temp;
         byte[] output;
         byte rep;
         public Transformer() {
         public byte[] transform(byte[] in) {
              input = in;
              temp = new byte[in.length];
              output = new byte[count(input, temp)];
              output = compress(temp, output);
              return output;
         private int count(byte[] from, byte[] to) {
              int k = 0; // total bytes copied so far
              byte markerByte = (byte) 0xE1;
              for (int i = 0, j = 0; i < from.length; i = j) {
                   for (j = i+1; j < from.length && from[j] == from[i] && j-i < 128; j++);
                   if (j-i >= 3) {
                        to[k++] = markerByte;
                        to[k++] = (byte) (j-i);
                        to[k++] = from[j-1];
                   } else {
                        to[k] = from[k];
                        k = i+1;
              return k;
            // (the following method isn't finished)
         private byte[] compress(byte[] from, byte[] to) {
              for (int i = 0; i < from.length; i++) {
                   if (from[i] == (byte) 0xE1) {
                        System.out.println("repeat");
                   System.out.println(from);
              return to;
         private byte getRepeatByte(int numberOfRepeats) {
              byte instruction;
              switch (numberOfRepeats) {
              case 1: instruction = (byte) 0xE1; break;
              case 2: instruction = (byte) 0xE2; break;
              case 3: instruction = (byte) 0xE3; break;
              case 4: instruction = (byte) 0xE4; break;
              case 5: instruction = (byte) 0xE5; break;
              case 6: instruction = (byte) 0xE6; break;
              case 7: instruction = (byte) 0xE7; break;
              case 8: instruction = (byte) 0xE8; break;
              case 9: instruction = (byte) 0xE9; break;
              case 10: instruction = (byte) 0xEA; break;
              case 11: instruction = (byte) 0xEB; break;
              case 12: instruction = (byte) 0xEC; break;
              case 13: instruction = (byte) 0xED; break;
              case 14: instruction = (byte) 0xEE; break;
              case 15: instruction = (byte) 0xEF; break;
              default: instruction = (byte) 0xE0; break;
              return instruction;
    At the moment I'm using a marker byte in the transform() but I want to be using the switch statement to work out the right byte to put in first.
    Does anyone have any advice on if I'm doing this in a ridiculous way or if my methods won't work.. As I haven't written a decompressor yet, it's pretty hard to test!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    baftos - thank you for your advice, i will try that and see how it goes.
    Jos - it is your method and thank you very much for it! It's part of an ongoing project of mine, which is turning out to be more challenging than i originally thought - when i posted on the other forum your loop did perfectly what I was trying to do at the time. I need all the advice i can get and hence post on multiple forums.

Maybe you are looking for