How to split an array (*not String*) into smaller arrays?

Hello,
let's say you have an array of bytes whith length (for example) 5000B. Now you want to split this array into smaller ones, for example 1500B. Then you will have 3 arrays of 1500B and another one of 500B. What I try to do then is the following:
pointer = 0;
size = source.length; // For example, size = 5000
maxsize = 1500;
while ((size - pointer) > maxsize) {
   byte[] dest = new byte[maxsize];
   System.arraycopy(src, pointer, dest, pointer, maxsize);  // <--- Errors here!
   pointer += maxsize;
   // Do some stuff here with the dest array
}There's no errors at compile time. But at runtime, the first iteration everything works OK (the 1500 first bytes are copied to the dest array). However, in the second iteration, the java interpreter claims:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)And I don't know what I'm doing bad. I guess there's a stupid question I can't see by myself... Help wanted, please!

> System.arraycopy(src, pointer, dest, pointer, maxsize);should be
System.arraycopy(src, pointer, dest, 0, maxsize);Since you're copying to the first position in the destination array.

Similar Messages

  • How do I split a comma delimited string into an array.

    I have a string that I am passing into a function that is Comma delimited. I want to split the string into an array. Is there a way to do this.
    Thanks in advance.

    trouble confirmed on 10gR1 and 10gR2
    works with 'a,b,c'  and also with  '  "1"  , "2"  ,  "3"  '
    does not work with '1,2,3' 
    throwing ORA-6512                                                                                                                                                                                                                                                                                                                           

  • How to break up a String into multiple array Strings?

    How do I break up a string into a bunch of String arrays after the line ends.
    For example,
    JTextArea area = new JTextArea();
    this is a string that i have entered in the area declared above
    now here is another sting that is in the same string/text area
    this is all being placed in one text field
    Sting input = area.getText();
    now how do I break that up into an array of strings after each line ends?

    Ok I tested it out and it works.
    So for future refrence to those that come by the same problem I had:
    To split up a string when using a textfield or textarea so that you can store seperate sections of the string based on sperate lines, using the following code:
    String text = area.getText() ;
    String[] lines = text.split("\n") ;
    This will store the following
    this is all one
    entered string
    into two arrays
    Cheers{
    Edited by: watwatacrazy on Oct 21, 2008 11:06 AM
    Edited by: watwatacrazy on Oct 21, 2008 11:16 AM
    Edited by: watwatacrazy on Oct 21, 2008 11:16 AM

  • In iPhoto 11, I know how to create new libraries.  I do not know how to split my existing large library into the new ones.

    In iPhoto 11, I know how to create new libraries.  I do not know how to split my large existing library into the new libraries?

    You need to use the iPhoto Library Manager.
    (66928)

  • Add an array of strings into ArrayList

    Hi Guys
    I would like to add an array of strings into an ArrayList, which i have implemented by using the following code:-
    String[] strReturnWords = getInput2(line);
    List.add(strReturnWords);strReturnWords returns an array of Strings.
    How do i retrieve the array of strings from the ArrayList. I have tried
    String[i] strString = List.toString();Am i doing this correctly, are their any other ways??
    Many thanks
    Jason

    That should work.NO. That wont work AT ALL.
    This:
    String[] arrayOfString = new String[listName.size()];Is not right. The number of elements in the list is MUCH different
    then the size of the array which is an element in the list.
    This:
    arrayOfStrings[ i] = (String)listName.get(i);Will fail. The list contains an Object of StringArray not an Object of String.
    import java.util.*;
    public class StringList{
    public static void main(String[] args){
         String text = "this is some text";
         String[] words = text.split("\\s+");
         ArrayList list = new ArrayList();
         list.add(words);
         String[] array = (String[])list.get(0);
         for(int i = 0; i < array.length; i++){
         System.out.println("Word: " + array);

  • Convert an array of strings into a single string

    Hi
    I am having trouble trying to figure out how to convert an array of strings into a single string.
    I am taking serial data via serial read in a loop to improve data transfer.  This means I am taking the data in chunks and these chunks are being dumped into an array.  However I want to combine all elements in the array into a single string (should be easy but I can't seem to make it work).
    In addition to this I would also like to then split the string by the comma separator so if any advice could be given on this it would be much appreciated.
    Many Thanks
    Ashley.

    Well, you don't even need to create the intermediary string array, right? This does exactly the same as CCs attachment:
    Back to your serial code:
    Why don't you built the array at the loop boundary? Same result.
    You could even built the string directly as shown here.
    Message Edited by altenbach on 12-20-2005 09:39 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    autoindexing.png ‏5 KB
    concatenate.png ‏5 KB
    StringToU32Array.png ‏3 KB

  • How to get input from keyboard scanner into an array

    This is probably a very basic question but I'm very new to java..
    My task is to reverse a string of five digits which have been entered using keyboard scanner.
    E.g. - Entered number - 45896
    Output - 69854
    I used the StringBuffer(inputString).reverse() command for this, but i need a more basic method to do this.
    I thought of defining an array of 5
    int[] array = new int [5];
    and then using,
    Scanner scan = new Scanner(System.in);
    to enter the numbers. But I can't figure out how to get the five input numbers into the array.
    If I can do this I can print the array in reverse order to get my result.
    Any other simple method is also welcome.

    Hey thanks for the quick reply,
    But how can I assign the whole five digit number into the array at once without asking to enter numbers separately?
    E.g. - if entered number is 65789
    Assign digits into positions,
    anArray [0] = 6;
    anArray [1] = 5;
    anArray [2] = 7;
    anArray [3] = 8;
    anArray [4] = 9;
    I'm really sorry but I am very new to the whole subject.

  • How to List files in a directory into an Array

    Does anyone know of the best way to load all of the files in a specified directory into an array. (not going into sub directories either).
    I was to be able to do something like this.... (pseudo)
    String directory = "C:\";
    String [] theList;
    do
    get next file name;
    add to theList;
    }while(!End of Directory)
    Done.

        public static void main(String args[]) {
         String directory = "C:\\";
         File dir = new File(directory);
         File [] theList = dir.listFiles();
         for(File file : theList)
             if(!file.isDirectory() && !file.isFile())
              System.out.println(file.getName());
         }This will list every item in the coot of C:\ that is not a file or a directory. Change the if statement to fit your needs.
    ~Tim

  • How to read and write a string into a txt.file

    Hi, I am now using BEA Workshop for Weblogic Platform version10. I am using J2EE is my programming language. The problem I encounter is as the above title; how to read and write a string into a txt.file with a specific root directory? Do you have any sample codes to reference?
    I hope someone can answer my question as soon as possible
    Thank you very much.

    Accessing the file system directly from a web app is a bad idea for several reasons. See http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html for a great discussion of the topic.
    On Weblogic there seems to be two ways to access files. First, use a File T3 connector from the console. Second, use java.net.URL with the file: protocol. The T3File object has been deprecated and suggests:
    Deprecated in WebLogic Server 6.1. Use java.net.URL.openConnection() instead.
    Edited by: m0smith on Mar 12, 2008 5:18 PM

  • How to print different colors of Strings into JEditorpane?

    How to print different colors of Strings into JEditorpane?
    Can any body give me answer ...

    JEditorPane contain HTML. So write your HTML using the color attribute.
    Start by read the the API description of JEditorPane. you will find a link to the Swing tutorial on "Using Text Components" which has working examples of using a JEditorPane. It also has an example of using a JTextPane where you can dynamically change the attributes of individual pieces of text.

  • Split string into an array (Skip first character)

    I have a string like:
    ,open,close,open
    I want to parse the data into an array (without the first ','). I found and tweaked the following code, but the result was:
    +<blank line> (think this is coming from the first ',')+
    off
    on
    off
    FUNCTION SPLIT (p_in_string VARCHAR2, p_delim VARCHAR2) RETURN t_array
    IS
    i number :=0;
    pos number :=0;
    lv_str varchar2(50) := p_in_string;
    strings t_array;
    BEGIN
    -- determine first chuck of string
    pos := instr(lv_str,p_delim,1,1);
    -- while there are chunks left, loop
    WHILE ( pos != 0) LOOP
    -- increment counter
    i := i + 1;
    -- create array element for chuck of string
    strings(i) := substr(lv_str,1,pos-1);
    -- remove chunk from string
    lv_str := substr(lv_str,pos+1,length(lv_str));
    -- determine next chunk
    pos := instr(lv_str,p_delim,1,1);
    -- no last chunk, add to array
    IF pos = 0 THEN
    strings(i+1) := lv_str;
    END IF;
    END LOOP;
    -- return array
    RETURN strings;
    END SPLIT;
    I am working on a 9i database.

    How is your collection defined? Assuming you are doing something like
    SQL> create type t_array as table of varchar2(100);
      2  /
    Type created.then you would just need to add an LTRIM to the code that initializes LV_STR and add appropriate EXTEND calls when you want to extend the nested table
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace FUNCTION SPLIT (p_in_string VARCHAR2, p_delim VARCHAR2)
      2    RETURN t_array
      3  IS
      4    i number :=0;
      5    pos number :=0;
      6    lv_str varchar2(50) := ltrim(p_in_string,p_delim);
      7    strings t_array := t_array();
      8  BEGIN
      9    -- determine first chuck of string
    10    pos := instr(lv_str,p_delim,1,1);
    11    -- while there are chunks left, loop
    12    WHILE ( pos != 0)
    13    LOOP
    14      -- increment counter
    15      i := i + 1;
    16      -- create array element for chuck of string
    17      strings.extend;
    18      strings(i) := substr(lv_str,1,pos-1);
    19      -- remove chunk from string
    20      lv_str := substr(lv_str,pos+1,length(lv_str));
    21      -- determine next chunk
    22      pos := instr(lv_str,p_delim,1,1);
    23      -- no last chunk, add to array
    24      IF pos = 0
    25      THEN
    26        strings.extend;
    27        strings(i+1) := lv_str;
    28      END IF;
    29    END LOOP;
    30    -- return array
    31    RETURN strings;
    32* END SPLIT;
    SQL> /
    Function created.
    SQL> select split( ',a,b,c', ',' ) from dual;
    SPLIT(',A,B,C',',')
    T_ARRAY('a', 'b', 'c')If T_ARRAY is defined as an associative array, you wouldn't need to have the EXTEND calls but then you couldn't call the function from SQL.
    Justin

  • Convert HEX String into HEX Array

    Hi!
    Probably a silly question, but I am looking for a way to convert a ROM ID number such as "5E03C21000BA" into an short hexadecimal array.
    The way to do this in C would probably be
    char[17] str_romID = "5E03C21000BA";
    uchar[8] romID;
    sscanf(str_romID, "%02X%02X%02X%02X%02X%02X%02X%02X",
    &romID[0], &romID[1], &romID[2], &romID[3],
    &romID[4], &romID[5], &romID[6], &romID[7]);
    but I can't seem to find a way to do this in LabVIEW. I would be very grateful if you could help me out with a sample program. Thanks ever so much!
    Stefan

    Hello Blondchen,
    I have attached a picture to my last explanation. This example doesn't take care of strings with an uneven number of chars!
    My array has only 6 numbers as you only gave a string with 12 chars... That's what I asked before: how should we know where to split your string to the single numbers? Normally I would take 2 chars to form a byte (as I did in the example). If you give me 16 chars I give you 8 bytes...
    I also think your C byte array will be an U8 array in LabView. If you REALLY need I8 numbers you can change the default type of the "hex to string" or cast to I8 (advanced->data manipulation->type cast) after the conversion.
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    ConvertHexHex.png ‏13 KB

  • How to split a parallell-page PDF into single-page PDF

    My situation: I have a few hundred pages of files I made quite a few years ago, optimized for "self-publishing" via the printer. I no longer have any source files (my own bad). These files have 2 pages next to each other in an A4 landscape PDF. I would like to change and combine these files into a US Letter portrait PDF.
    I have browsed earlier, similar threads, most notably the most referred to thread:
    http://forums.adobe.com/message/3331516
    which recommends using Adobe PDF printer. However, as this thread points out, and as I for one have found on my own system (10.8.3), Adobe PDF printer is no longer an option on Mac OS X (version 10.6 and on):
    http://forums.adobe.com/thread/556366
    So the question then is: How do we now split double-page landscape PDFs into single-page portrait PDFs?

    Since at least OSX.5 adobe has removed PDF Printer which was begining to fail it was written in Adobe's altered version of javascript and it was a wonder it was working to begin with They replaced it with an Automator action that's called up through the print Driver.
    Here are the steps for applications other than Acrobat.
    create you doucument. laying it out the way you want it.
    Go to Print menu.
    click and hold the pdf button - a context menu pops up.
    now scan the list of choices and choose Adobe PDF or Adobe Quality PDF (depends on version of OS)
    wait for direction fields to come up and make the desired choices (the first screen is basically job options).
    when asked ask for name either ecept name give or choose name of your choice.
    Browse to desired location for file
    then click save.
    How the PDF is layed out in acrobat is determinedby acrobat. Adobe add an additional Layer on top of the Print Driver. You can by pass it and use the Print Driver but if there is an orientation switch in your docment the page is turned so everything comes out with same edge of Paper
    Oh, look out for a Grand idea Adobe did that even Forest Gump would have left alone.
    If you want to do duplex printing to a PDF with more than one page you won't be able to do so whether you have your printer setup for duplex printing. You can go back and forth from printer setting s to Printer setting toggling off and on til you turn blue in the face. You have to go into the document properties and loo for a command called SIMPLEX printing its on by default and needs to be turned off. Even my cat Boots would be smart enough not to put that in.
    This settinging does not permanently turn off and you have to do with each document you create or resave.

  • How can i combine an array of string and an array of integers ?

    i have an array of string data [to be used as header], and an array of multiple column integer vakues;i need them together in one file. 
    Am not able to combine them so that i can write them into a single file.
    Solved!
    Go to Solution.
    Attachments:
    string file input.txt ‏1 KB
    Test build_1.vi ‏13 KB

    There are a few ways you can do this.  What I recommend is:
    Open the file
    Use the Array to Spreadsheet String to turn your headers into a single string
    Write this to the file.
    Use the Array to Spreadsheet String to turn your numeric data into a single string
    Write this to the file.
    Close the file
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How do I read directly from file into byte array

    I am reading an image from a file into a BuffertedImage then writing it out again into an array of bytes which I store and use later on in the program. Currently Im doing this in two stages is there a way to do it it one go to speed things up.
    try
                //Read File Contents into a Buffered Image
                /** BUG 4705399: There was a problem with some jpegs taking ages to load turns out to be
                 * (at least partially) a problem with non-standard colour models, which is why we set the
                 * destination colour model. The side effect should be standard colour model in subsequent reading.
                BufferedImage bi = null;
                ImageReader ir = null;
                ImageInputStream stream =  ImageIO.createImageInputStream(new File(path));
                final Iterator i = ImageIO.getImageReaders(stream);
                if (i.hasNext())
                    ir = (ImageReader) i.next();
                    ir.setInput(stream);
                    ImageReadParam param = ir.getDefaultReadParam();
                    ImageTypeSpecifier typeToUse = null;
                    for (Iterator i2 = ir.getImageTypes(0); i2.hasNext();)
                        ImageTypeSpecifier type = (ImageTypeSpecifier) i2.next();
                        if (type.getColorModel().getColorSpace().isCS_sRGB())
                            typeToUse = type;
                    if (typeToUse != null)
                        param.setDestinationType(typeToUse);
                    bi = ir.read(0, param);
                    //ir.dispose(); seem to reference this in write
                    //stream.close();
                //Write Buffered Image to Byte ArrayOutput Stream
                if (bi != null)
                    //Convert to byte array
                    final ByteArrayOutputStream output = new ByteArrayOutputStream();
                    //Try and find corresponding writer for reader but if not possible
                    //we use JPG (which is always installed) instead.
                    final ImageWriter iw = ImageIO.getImageWriter(ir);
                    if (iw != null)
                        if (ImageIO.write(bi, ir.getFormatName(), new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Unable to Write Image");
                    else
                        if (ImageIO.write(bi, "JPG", new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Warning Unable to Write Image as JPEG");
                    //Add to image list
                    final byte[] imageData = output.toByteArray();
                    Images.addImage(imageData);
                  

    If you don't need to manipulate the image in any way I would suggest you just read the image file directly into a byte array (without ImageReader) and then create the BufferedImage from that byte array.

Maybe you are looking for

  • How can I set up a unique signature for each email account?

    Is Apple kidding me? I can put multiple email accounts on my iPad but they must all have the same signature, bcc settings etc... That makes this a toy not a tool! Is there an app for that? RA

  • The volume for "Untitled CD" cannot be found

    I have an "Untitled CD" that I cannot delete. I am running OS X. Any thoughts? When I click on the file I immediately get an error message. It is impossible to drag the file out of the sidebar.

  • Error with HTTP Adapter

    Hi all, I have a scenario in which i am sending an IDoc to a Oracle Table. This sends back an acknowledgement to an HTTP Receiver which is finally sent as an ALEAUD Idoc to the sender system. The data is getting posted to the table and the acknowledg

  • Do's, Don'ts and Never for first time users

    I work within a global organisation - with many people turning to Captivate for the first time. We all share the same LMS. I want to create a short "check-list" of the most important Captivate Preference / Settings or ways of working  to help new use

  • VMWare Problem about running OS

    Hi there my kernel is 2.6.26 and i installed vmware-server also any any patch 117d everything seems ok but when i try to run any OS image, there is an error says Unable to change virtual machine power state: The process exited with an error: End of e