If reading file as bytes (DataInputStream), how find delimiter?

I have to read a file in as a DataInputStream because it is really two files (one text, one can be a .doc, .jpg, etc) mixed into one. The files are separated by a delimiter which is something like: "--34f5s--a23--34d--". The binary file data is also ended by that delimiter as well. So how would I find the delimiters while not converting the byte stream and losing data?

You're probably not going to like this suggestion...
The only way I can think of off the top of my head is to get the byte array representation of the delimiter, and as each byte passes through your InputStream, compare it with the delimiter array, finite-state-machine-style.
Send the data on if it doesn't match, otherwise keep matching against the delimiter. If you match halfway and the mismatch, send on the bytes that matched as well as the last byte which didn't. If you match to the end of the delimiter, then the first file is (should be) exactly what you sent on.
Alternatively, assuming this is for a MIME-style attachment, is there anything in javax.mail that would do this for you? Or another third-party library?

Similar Messages

  • I have lost the toolbar that reads "File" "Edit" etc. How do I get it back?

    I have lost the toolbar that reads "File" "Edit" etc. How do I get it back?

    Firefox 3.6+ versions have a feature to allow the user to hide the Menu bar.
    Hit the '''Alt''' key to temporarily show the Menu bar, then open View > Toolbars and select Menu bar, so it has a check-mark. <br />
    The F10 can also be used on most PC's to temporarily reveal the Menu bar.
    https://support.mozilla.com/en-US/kb/Menu+bar+is+missing

  • Reading file containing byte data

    I am trying to read a file containing data that is in byte format. I can't look at the file and have no idea what is in there. For my first pass I would just like to see what the format is of the data in characters. Is there an easy way to do this? This is what I have done so far:
    //file is read from another method and is passed in here.
    try {
    BufferedReader f = new BufferedReader(new FileReader(file));
    String t;
    while ((t = f.readLine()) != null) {
    byte b[] = t.getBytes();
    System.out.println("bytes " + b[0]);
    System.out.println("chars " + (char)b[0]);
    catch(Exception e) {
    e.printStackTrace();
    The output is looking like this:
    bytes 72
    chars H
    bytes 74
    chars J
    bytes 81
    chars Q
    bytes -56
    chars ?
    Which one is the character value of the bytes? I am assuming the char one, but it sure seems like funny values. Also, I want to read the whole line and then get the whole line converted, not just the first byte. Isn't getBytes just getting the first byte? How can I convert the whole line after it is read (f.readLine())?
    Thanks.
    Allyson

    Well, I tried that and it still gives me just the binary or byte data (I have no idea what kind it is - I know I can't read it when I try to open it with notepad). There is a current application that uses this file and opens it and provides the data when it is opened. I am trying to look thru that code to find out what it does, but it is very confusing. It is written in c.
    Any other ideas out there as to how to open and display the correct data in a file like this? When I did the binary data open this is the kind of data I got:
    char in new loop Q
    char in new loop
    char in new loop @
    char in new loop
    char in new loop @
    char in new loop @
    char in new loop
    char in new loop
    char in new loop @
    char in new loop L
    char in new loop `
    char in new loop :
    char in new loop @
    I know that data is mostly numbers and maybe a few names, but nothing like that.
    Thanks.
    Allyson

  • Reading file in bytes using FileReader...

    Hi,
    I am trying to read out bytes value from a .bmp file then i try to change the byte values that i read out to hexadecimal value.
    I open the .bmp in Win Hex (a software) but the hexadecimal value does not tally....
    public void readByteFile (String path)
    Vector in = new Vector ();
    try
    FileReader reader = new FileReader (path);
    int c;
    while ((c = reader.read ()) != -1)
    String hex = Integer.toHexString (c);
    reader.close ();
    } catch (FileNotFoundException e) {System.err.println(e);}
    catch (IOException e) {System.err.println(e);}
              return in;
         }

    If you want to read the actual bytes from the file then do not use a Reader. That will convert the bytes to characters as if they were text. Use an InputStream instead.

  • 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.

  • FW: [Adobe Reader] I want my credit card information to be removed from Adobe's file and I can't find a phone number to contact someone in your company, how come, please help!  Lucie

    What a dumb answer, the payment is done and charged already,
    ADOBE DOES NEED MY CREDIT CARD INFO ANYMORE, PLEASE REMOVE IT
    FROM YOUR DATABASE AS I CANNOT DO IT MYSELF.  It is quite annoying
    to be controlled like this, please confirm that my request has been answering
    with intelligence please.
    Lucie Lévesque
    Date: Mon, 8 Dec 2014 08:09:59 -0800
    From: [email protected]
    To: [email protected]
    Subject:  I want my credit card information to be removed from Adobe's file and I can't find a phone number to contact someone in your company, how come, please help!  Lucie
        I want my credit card information to be removed from Adobe's file and I can't find a phone number to contact someone in your company, how come, please help!  Lucie
        created by Bernd Alheit in Adobe Reader - View the full discussion
    Adobe needs the credit card information for the payments.
         If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/6995243#6995243 and clicking ‘Correct’ below the answer
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:
    Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/6995243#6995243
         To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"
         Start a new discussion in Adobe Reader by email or at Adobe Community
      For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624.

    Adobe Reader is a FREE program, so you would not enter a credit card
    If you have a subscription to a PAID program, removing your credit card information would cause that program to stop working when you stop paying for your subscription
    If that is what you want, here is the information on how to cancel
    Cancel http://helpx.adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • I have problem with Itunes losing where podcasts and some purchased music is located. Don't know how Itunes losing the locations of the files and I can't find the files on my hard drive. What can I do to stop Itunes losing location and restore my files?

    I have problem with Itunes losing where podcasts and some purchased music is located. Don't know how Itunes losing the locations of the files and I can't find the files on my hard drive. What can I do to stop Itunes losing location and restore my files?

    Try assigning Queen as the Album Artist on the compilations in iTunes on your computer.

  • How can I delete multiple files at a time from "Finder"

    I can't possible delete the thousands of junk files that showed up in Finder once I downloaded Maverick.  I can't delete more than one at a time now.  Why won't the highlighting stay in place on more than one file that I want to delete?

    How are you trying to select multiple files?
    What makes you think that "thousands of junk files [...] showed up in Finder once I downloaded Maverick" (or even installed it)?

  • I have copied over my music file to a new computer and the music shows on itunes but wont play. When I track where the song is located it is reading the wrong information. How do I change this as Edit Preferences has the right location

    I have copied over my music files to a new computer and the music shows on itunes but wont play. When I track where the song is located it is reading the wrong information. How do I change this as Edit>Preferences has the right location?

    Select one of the tracks with a broken link, press ctrl-i to Get Info. Say No when iTunes asks if you would like to locate the track, then look at the Summary tab for the location expects to find the file in.
    Now try to locate the file in question. The two locations should give a clue as to what to do next.
    Here is an example with a file I've deliberately moved from the new layout to the old pre-iTunes 9 layout.
    This means iTunes is expecting to find the file at:
    D:\iTunes\iTunes Media\Music\a-ha\Take On Me\01 Take On Me.mp3
    but it isn't there because I've moved it to:
    D:\iTunes\iTunes Media\a-ha\Take On Me\01 Take On Me.mp3
    which is where it would have lived back in iTunes 8 (though the media folder would have been called iTunes Music back then as well).
    If you can provide the expected and actual locations of a broken track I should be able to suggest the easiest way to resolve things.
    tt2

  • File History split 1 gig file in to 5 200 meg files, and I can't find how to restore this file

    I setup file restore on a Windows 8 computer.
    Backed up all the files to a NAS.
    Wiped and reloaded 8.1 pro and did a file restore.
    All of my files, except one large file, restored.
    The file that didn't was a 1 gig TrueCrypt (VeraCrypt) file in the root of "documents".
    When I browse out to my NAS, I see 5 files.
    One of them is named: TCvol (2014_12_09 02_17_05 UTC) and it is 200 megs.
    I believe these 5 files need to combine themselves again to restore my original 1 gig file, but I cannot find any documentation.
    Pretty much everything shows that you open file history restore and your data should appear there.

    Hi,
    It should be caused that Windows Server Backup cannot recognize the encrypted file - I cannot confirm how the third party application (TrueCrypt) work, it seems that it will split an encrypted file into several files and Windows Server Backup only restored
    files physically. You can contact TrueCrypt support about this issue. 
    I searched on your website and found several threads which related to get TrueCrypt working with Windows Server Backup. Specifically to your current issue you can confirm with them about any suggestion to get file recovered or how to do such backup job for
    a healthy recovery. 
    https://veracrypt.codeplex.com/discussions/581529
    https://veracrypt.codeplex.com/discussions/577924
    Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
    Please remember to mark the replies as answers if they help and un-mark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • My operating system is Snow Leopard Version 10.6.8.  I moved files in Adobe Bridge, how do I sinc to Finder?

    My operating system is Snow Leopard, Version 10.6.8.  I rearranged files in Adobe Bridge, how do I sinc my Finder?

    10.5.8 is Leopard, not Snow Leopard. You need the Snow Leopard DVD;
    You can get it only by phone now from Apple.
    In the US, call 1-800-MY-APPLE and ask for a sales assistant. Last quoted price was $19.99 for the single-user and $29.99 for the family licence.
    For other countries, check here; http://support.apple.com/kb/HE57
    Don't forget to ask for Sales; the tech support guys can't help.
    If you want Lion, rather than Mountain Lion, the same Sales team can give you a download code to use at the Mac AppStore.
    To get the App Store, you need to update your new Snow Leopard from 10.6.3 (which is the version on the installer) to 10.6.8 with the combo update; http://support.apple.com/kb/DL1399
    Be warned that the upgrades will render a lot of older software unusable, and will need new drivers for printers and scanners in all likelihood.

  • HOW to read file using ftp???

    Hi to all,
    I have problem with reading file using ftp connection, i want to read only 1024 bytes for one time, and i have
    next code wich read this:
    byte buffer[] = new byte[1024];
    while( (readCount = input.read(buffer)) > 0) {
    bos.write(buffer, 0, readCount);
    but I dont know how to put all read data in one byte[] if i dont know length of file.
    I can't do some like: byte file[] = new file[1000000];
    Thanks for all sugestions!

          * Download a file from a FTP server. A FTP URL is generated with the following syntax:
         * <code>ftp://user:password@host:port/filePath;type=i</code>.
          * @param ftpServer FTP server address (incl. optional port ':portNumber').
          * @param user Optional user name to login.
          * @param pwd Optional password for <i>user</i>.
          * @param fileName Name of file to download (with optional preceeding relative path, e.g. one/two/three.txt).
          * @param destination Destination file to save.
         * @throws MalformedURLException, IOException on error.
         public void download(String ftpServer, String user, String pwd, String fileName, File destination) throws MalformedURLException, IOException {
            if (ftpServer != null && fileName != null && destination != null) {
                StringBuffer sb = new StringBuffer("ftp://");
                if (user != null && pwd != null) { //need authentication?
                    sb.append(user);
                    sb.append(':');
                    sb.append(pwd);
                    sb.append('@');
                }//else: anonymous access
                sb.append(ftpServer);
                sb.append('/');
                sb.append(fileName);
                sb.append(";type=i"); //a=ASCII mode, i=image (binary) mode, d= file directory listing
                BufferedInputStream bis = null;
                BufferedOutputStream bos = null;
                try {
                    URL url = new URL(sb.toString());
                    URLConnection urlc = url.openConnection();
                    bis = new BufferedInputStream(urlc.getInputStream());
                    bos = new BufferedOutputStream(new FileOutputStream(destination.getName()));
                    int i;
                    while ((i = bis.read()) != -1) { //read next byte until end of stream
                        bos.write(i);
                    }//next byte
                } finally {
                    if (bis != null) try { bis.close(); } catch (IOException ioe) { /* ignore*/ }
                    if (bos != null) try { bos.close(); } catch (IOException ioe) { /* ignore*/ }
            }//else: input unavailable
        }//download()If you don't want to strore the data into a file, use ByteArrayOutputStream instead of a FileOutputStream.

  • How to open multiple folders and read file?

    Hello,
    I try to use this bridge script. The script work very well for me but some times I have multiple folders.
    Now script work that:
    1. Read file in folder
    2. Save text file and show me popup with full quadrature
    http://forums.adobe.com/message/3996179?tstart=56
    1. Open folder
    2. Read file
    3. Close folder
    4. Read next folder
    5. Read file
    6. Close folder
    7. ....
    8. Save text file with all folders and show me popup with full quadrature
    Please help!
    Best regards.

    Lightwave wrote:
    I don't think you guys are hearing my question. I can see how to restore a single file or folder.
    I want to restore ALL the changed or deleted files and folders since my last backup (but not the entire disk, that would be unnecessary)
    Were all (or most) of the items in, say, your Documents folder, or your Music folder? If so, you can restore the whole folder via TM. That will put all sub-folders and files back exactly the way they were at the time of the backup. You just have to be careful to pick the right backup (date & time).
    Or, if they were scattered through your Home Folder, you can restore that entire folder in the same way.
    If you've made changes subsequent to that backup, however, they will be lost in the process. What you can do in that case is, restore to a different location, then compare the two folders, and drag & drop what you want. (To restore to a different location, select the folder in TM, then click the "gear" icon in the TM Finder window, and select +Restore <item selected> to ...+ and you'll be prompted for a restore location.)

  • Trying to read a file but doesnt know how to get the size of the inputstrem

    hi im trying to read a file in a cel this is my code:
    fconn = (FileConnection)Connector.open("file://localhost/" + actualdir);                     
    InputStream fis = fconn.openInputStream();                                                 
    byte b[] = new byte[1024];                                                                         
    fis.read(b);                         
    fis.close();
    fconn.close();   
    textBox1 = new TextBox("Viendo el Archivo: " + list1.getString(list1.getSelectedIndex()), null, 1024,TextField.ANY | TextField.UNEDITABLE);                       
                              textBox1.setString(new String(b, 0, b.length));                        i dont want to create always an array of bytes of size 1024 instead i wanna know how many bytes does inputstream object has, how can i know that?

    you can either retrieve the whole file at once by determine the file size like:
    fconn = (FileConnection)Connector.open("file://localhost/" + actualdir);
    InputStream fis = fconn.openInputStream();
    byte b[] = new byte[fconn.fileSize()];
    fis.read(b);
    fis.close();
    fconn.close();
    or read every single byte
    fconn = (FileConnection)Connector.open("file://localhost/" + actualdir);
    InputStream fis = fconn.openInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int i = fis.read();
    while(i != -1){
    baos.write(i);
    fis.read();
    String content = new String(baos.toByteArray());

  • New to J2ME, dont know how to read files on phone mem

    i check all the .io packages, still cant find any class that would help me to read files on phone memory.
    and i see that javax.microedition.media.Manager.createPlayer(String locator), require a string input argu. how can i make this string locator point to a media file on phone memory of TF-card.
    i heard Kjava has some packages from j2se, is there any class would help me? plz someone give me a link of Kjava reference, i cant find it anywhere, thx a lot!

    oh~~~no!
    i am afraid i cant enjoy myself with file conn.
    i tried several times, only to get a "Security Exception", and i contacted with moto dev center, they say that unless i have a cert, i cant use file conn API and many other APIs that is defined as restricted!!!
    and for the cert, if i have a biz relation with moto, they could give a "Develop Certification", or i must pay a third party to get a cert...
    what a world~~~~~~~~~~~is unfair!!!

Maybe you are looking for

  • External processing badi BAdI PP_OM_BD_BANF_HEADER_MATERIAL

    Hi,   Please any one can help me regarding this badi implementation and explain the process flow of the scenario. I have 5 operations and operation 3 is external processing 1.   once purchase order is created which material is supplied to vendor. 2. 

  • Automatic stop play(music) on itouch or newer ipod?

    Hello, I have used ipod on gigs for backing tracks from my seqeunces,etc... I was wondering if the itouch will allow you to set the song list(s) up to play one song at a time? Similar to the playlists in itunes? I've been using an older ibook lately

  • 24" LED display just DIED!!!!

    My 24" LED display has been working without issue connected to my Mac Mini server, but tonight just started flickering (mostly black with an occasional split second glimpse at a blue screen then straight to black again). I shut the Mac Mini down (hel

  • Error MDDataSetBW.GetCellData (WIS 10901)

    Hi all, Iu2019m working with Business Objects series XI 3.1 and SAP BI. It give me the following error when I try to refresh a query in WebI after add on an additional characteristics. If remove that any characteristic, it works fine. "...MDDataSetBW

  • Microsoft Report Error

    Hi everybody, is there anyone who can explain me what to do when this message comes: "Microsoft Report Error"? Since this morning I have been trying to use word, I open the document, I start working with it and after 5-10 minutes the computer crashes