DataOutputStream / DataInputStream   ( Losing information? )

I have written a client server program. The client program establishes a URL connection to a ServerSocket. I am using a DataOutputStream to pass a large amount of data back to the client. The problem is that it appears that every now and then a byte is skipped or lost. Here is the important part of the code. (psudo) This loss appears to happen when I read the bytes into the Buf Array.
On the ServerSide :
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(os));
while (notcomplete){
       dos.writeInt(acuiredInt);
       dos.writeLong(acuiredLong);
        byte[] acuiredBuf ;
        for(int i=0; i < acuiredBuf; i++)
                  dos.writeByte( acuiredBuf) ;
On the Client Side
DataInputStream dis = new DataInputStream(new BufferedInputStream(os));
while (notcomplete){
       dis.readLong(acuiredLong);
       dis.readInt(acuiredInt);
        byte[] acuiredBuf  = new byte[1024];  //always the same size
        for(int i=0; i < acuiredBuf; i++)
                  dis.readByte( ) ;
}I know that one byte is being lost because I tried to send the same int value acros constantly, and then instead of calling readInt, i called readByte four times (four bytes of an int) , and gradually everytime the mysterios 'loss' happend, the values would shift. See my example:
Should Be:  
              1    =>       0 , 0 , 0 , 10      
              2    =>       0 , 0 , 10 , 020 
              3    =>       0 , 10, 152, 102    etc. 1 <= This displays lets say 500 times and is the correct Representation of the int then...
2 <= The 020 is not correct, it should be like the line above. This means that the first 0 has disapeared. (But when i check the last entry in the Buf, the 0 is there) . Afer even some more time it becomes the 3rd line. and the first two zeros are the last two entries in the Buf array.
So i dont' know if i'm losing information? Using the streams wrong, or how to fix it. All i want to do is pass a large amount of information from the server to the client.
Any help would be greatly appreciated.

In your loop, what aren't you checking the byte array's length rather than comparing against the byte array itself? Does that even compile? Post the actual code that is having issues.
Also, flushing after writing a single byte is a huge waste. Flush after a 'message' from the client is complete to send to the server and vice versa.
- Saish

Similar Messages

  • We have 3, soon to be 4 iphones under one contract.  How do we separate our iphones to have separate icloud accounts without losing information already stored?

    We have 3, soon to be 4 iphones under one contract.  How do we separate our iphones to have separate icloud accounts without losing information already stored?

    One of them can keep the current account.  Since the iCloud email account must stay with the current account, whoever uses it for email might be the best one to keep it.  You can then migrate the other phones to separate accounts, along with a copy of the data.  To do this, start by saving any photo stream photos that you want to keep to your camera roll (unless already there) by opening your my photo stream album, tapping Select, tapping the photos, tap the share icon (box with upward facing arrow), then tapping Save to Camera Roll.  If you are syncing notes with iCloud that you want to keep, you'll need to open each of your notes and email them to yourself so you can later copy and paste the text into new notes created in your new account.  Then go to Settings>iCloud, tap Delete Account (which only deletes it from this device, not from iCloud), choose Keep on My iDevice and provide the password to turn off Find My iPhone.  Then sign back in with a different Apple ID to create the new account and choose Merge to upload the data.
    Once all the phones are on separate accounts, you can each go to icloud.com and delete each other's data from your accounts.

  • [SOLVED]Mutt - abook problem - losing information

    I've experienced the problem seen by others with abook losing information, but I have not seen any clear solutions. I'm using mutt from extra, compiled via abs with the sidebar patch. It appears that the data loss happens when you have existing phone/address information, then add another contact with phone/address info. All previous entries then lose their non-email information. The email address stay, it's just the other info that disappears.
    I'm no C programmer, so I can't delve into the code. Anyone else care to take a crack at this? There don't seem to be any equivalent cli addressbooks out there, after some googling around.
    Thanks!
    Scott
    Last edited by firecat53 (2009-07-19 18:11:44)

    Hi Scott.... took a look with interest at todo.txt then asked myself, "what the heck am i thinking!"
    things like abook and calcurse and newsbeuter etc. etc. running in screen is what I'm thinking is where my efforts should be. Then again I guess todo.txt script can be run there also....
    geez... I'm just starting to get a bit advanced in a few areas so I think I'll stay with what's big with the gurus. should be of much interest to others who find out about it here and the future, who knows! I've sure had some laughs at the circles I've enjoyed over the years, if that makes enough sense.
    SO: abook still loosing all data, blank totally and I have to reboot and copy my backup in with abook NOT running generally for it to pick it up and load it. Like, IF I have abook running and copy the backup in, then quit abook and restart it's blank again. usually.
    ... I think I'll email cedric the writer again. He was great and most interested in the data loss. This was a few months back, though we didn't get too far due to my not being able to provide much.
    Last edited by yvonney (2009-07-25 23:32:13)

  • Externalizable vs DataOutputStream/DataInputStream (Storable Interface)

    I have created an interface Storable as below which I use to save a complex Object to a byte array and ultimately to a database. The total processing time is 1hour and 5 minutes.
    public interface Storable
         void readData(DataInputStream in) throws IOException;
         void writeData(DataOutputStream out) throws IOException;
    I then swapped to Externalizable.
    I changed the top Object readData/writeData functions to
    readExternal and writeExternal.
    Then I added new readData/writeData functions to the contained Objects
    as below - so these objects are "new"ed and filled in by my code.
    void readData(InputObject in) throws IOException;
    void writeData(OutputObject out) throws IOException;
    Total processing time was reduced to 33minutes.
    Can anybody explain this >50% speed improvement?
    Also I would rather not use Externalizable so I can decouple the persisted data away from the Java code but it looks like one heck of a time penalty for doing so.

    The point is the only difference between the code I have written is that one is using
    ObjectInput/ObjectOutput (Externalizable) (34 minutes)
    the other is using
    DataOutputStream/DataInputStream (Storable) (1hour 5 minutes)
    and my code for the 2 methods is basically the same.
    This would lead to the conclusion that one of or both Java classes DataOutputStream/DataInputStream are very inefficient and I want to know why?

  • When I export my photos and save them as a jpeg.  Am I still losing information?

    When I export my photos and save them as a jpeg.  Am I still losing information?  Would I be better of saving them as a TIFF or a PSD?  Also I know DNG is a digital negative, would that be the better format to save all my stuff?

    I apologize if you already thoroughly know all this (I couldn't be sure):
    When you export, you don't change the original (i.e. you never overwrite the original). So, you can export a million times and never lose quality (of the original), regardless of the export formats you choose.
    Of course the quality of the export depends on the chosen format, and if the format is lossy (e.g. jpeg), then export quality also depends on the size & quality settings.
    TIFF is lossless, so quality is essentially equivalent to the raw in Lightroom. It's the preferred format if a really BIG file is OK. Jpeg was invented to reduce file-size as much as possible without being too much inferior, quality-wise - and it does that very well.
    DNG is good for some stuff, but don't export your photos in DNG format unless you know what you are doing and why... Lot's of people like converting their originals to DNG format, but that's a whole different kettle of fish...
    Note, it may very well make sense to export a jpeg as tiff, since exporting a jpeg as jpeg is not as good. - reminder: when you export, you are not overwriting the original, you are making a new copy from the original, by combining it with develop edits if there have been any.
    Rob

  • Synchronize contacts and calendar on 2 different computers without music and video pictures etc .... without losing information on my iphone ..... help

    computers without music and video pictures etc .... without losing information on my iphone ..... help

    This can be done without having to sync contacts and calendar events direct with a supported application via the iTunes sync process on each computer.
    This can be done over the air with a free iCloud account.

  • Using DataOutputStream/DataInputStream

    Hi, evveryone.
    I'm needing to use an applet, and this applet uses the following code.
    URL hp = new URL(stringURL);
    URLConnection hpCon = hp.openConnection();
    DataOutputStream dataoutputstream = new DataOutputStream(hpCon.getOutputStream());
    dataoutputstream.writeBytes(DataToSend);
    dataoutputstream.flush();
    dataoutputstream.close();
    DataInputStream datainputstream = new DataInputStream(hpCon.getInputStream());
    Mydoubts are:
    One: the URL used in URLConnection can be an asp page that uses JavaScript, or it must be an pure HTML, or an CGI, etc...
    Two: how, in this URL, can I retrieve the information of DataOutputStream ( I think that is through Request.DataInputStream, but I'm not sure, though ) , and then parse it to a String?
    Third: How I must sent the information that the Applet is waiting ( by an DataInputStreamReader ) back to it? The information is a String.
    Thanks,
    Mivil

    The Usage of URL objects can be facilitated by the following code.
    * Connect to the aURL use the aQueryString
    * as the request parameters and return the
    * data Stream.
    public static InputStream getHTTPResponse(String aURL, String aQueryString) throws MalformedURLException, IOException
    URL url = new URL(aURL);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    if (aQueryString != null)
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.println(aQueryString);
    out.close();
    return connection.getInputStream();
    * Connect to the aURL use the aQueryString
    * as the request parameters and return the
    * String response (when expected).
    public static String getHTTPResponseString(String aURL, String aQueryString) throws MalformedURLException, IOException
    InputStreamReader ipstr = new InputStreamReader(getHTTPResponse(aURL, aQueryString));
    BufferedReader reader = new BufferedReader(ipstr);
    String inputLine;
    StringBuffer sbuf = new StringBuffer();
    while ((inputLine = reader.readLine()) != null)
    sbuf.append(inputLine);
    reader.close();
    ipstr.close();
    return new String(sbuf);
    Regards

  • Is there a way to change the PSI settings of scanned papers w/o losing information?

    Hello - We have gotten a Kodak scanner and a program that it came with to scan old files (real files, not computer files) for storage, so we could free up some space. We've just started using this, but I have a question about the PDF files that we're left with.
    To begin with, the scanner is set at 600psi, hoefully we can change that, and the Kodak program that it came with. I think the program reads the text in the scans to save as memory. When they're finished, we can look up a name, word, date, location.... to search for and it automatically will give us a list of the locations.
    Here's question number one, if we change the PSI settings to 150psi or 72psi, will it still get that info, or does it have to stay at 600psi for the text info?
    Second, we now have the scans that we scanned at 600psi, but the files are huge!!!  2000 pages = 400MB - Is there a way to lower the PSI and still have the data of the pages stay in the files? It is very hard to work with a 400MB file with 2000 pages without my Acrobat freezing up, and yes, it is a full Acrobat 8 program and not just a reader. I know in Photoshop/Illustrator, I can change the psi and the file size shrinks, but it also changes the options of printing it later on.
    Just trying to find out some other info before we go any further.
    Thanks for any help, I know I'm going to be asked what model scanner and Kodak program we're using, but I currently don't have that info. Just wondering about the information being erased if the PSI file is downsized.
    Sean

    I would keep it at the 600 absolutely no less than 300. The higher the DPI the more likely the accuracy of the conversion is. You end up with too many artifacts that can't be converted when you go below 300.
    You and always optimize the PDF after the conversion.

  • How to sync iPhone 3GS to new computer without losing information

    As my last computer was dying I was able to create a backup disk on itunes to use with my new computer. When I got my new computer, I put in the disk and had no problems transferring all of my songs, pictures, and videos to my new itunes. Now when I want to sync my iphone to my new computer it is saying that I must erase and resync with the new computer, but I am worried that I will lose all of my contacts and other information that I have stored on my iphone. Can anyone tell me if this is a legitimate concern, and if so what I can do to keep my contacts, mail, and other information on my phone but at the same time be able to put my new songs on my phone as well.
    Thanks in advance for any help!

    Do the following & you'll be OK since you've moved your itunes library:
    First, disable auto sync when an ipod/iphone is connected, under preferences in itunes, which in windows is in the edit menu.
    Connect your phone, DO NOT SYNC.
    Next, go up to Store>Authorize this computer.
    Next, File>Transfer Purchases.
    Next, make sure you have at least one contact & one event in whatever supported program you use for that purpose. They can be fake, it doesn't matter.
    Right click the phone in the device pane & select "Reset Warnings".
    Next, right click again & select BACKUP.
    Next, restore your phone from the backup you just made.
    This must be followed by a sync to restore your itunes content. Which is selected from the various tabs. You should get a prompt regarding your contacts & calendar asking to "merge" or "replace", when you sync. Select "merge"
    This is what's included in the backup you'll make & restore from:
    http://support.apple.com/kb/HT1766
    This is how to restore from that backup, as already referenced, when prompted to create another backup before you restore, decline as we will use the backup we made when we started:
    http://support.apple.com/kb/HT1414

  • Update iPad without losing information

    Hello everyone, so i just joined the apple cult and bought a mac mini to replace my old pc that died.  Im not to familiar with the mac way of operating so bear with me.  I just got done upadting all the software for the mac mini and then I plugged in my ipad so it could get the update 5.1 or whatever it is.  However I tunes is saying it will erase all the apps/music/pictures etc that are on there.  There isnt anything yet on the mac mini as its still on my backup hard drive.  HOw can I update my ipad without losing everything and having to reload it onto the ipad?  Thanks
    Kila

    Disregad, i got it.

  • How rewrite cd's to Lossless without losing information writen in library

    Dear all
    I've about 700 cd's imported to iTunes with high compression.
    Now I've bought a new computer with a bigger capacity, and I want to rewrite all cd's to LossLess. My problem is how to do it without having to rewrite again all the information about genre, composer, titles, etc that I've organized
    when I first imported every cd.
    Thanks a lot to the one able to save me tones of work.
    Haddock

    Katrina's suggestion should work.
    HOWEVER--
    Even if you plan on tossing the original music files, make a backup of them prior to re-importing them into Lossless.
    If you have a problem, you may need the original files with their embedded metadata: those attributes stored in the song file, not the Library database file.
    Best of Luck

  • 9iasR2, rwservlet, jsp report, output pdf HttpSession losing information

    Hi,
    I think this is actually something I'm doing wrong with JDeveloper/my understanding of HttpSession, so I'm posting here after getting no help from the Reports folks.
    I have a number of .jsp reports and our application also generates letters for the users with Reports server. We use http://server/reports/rwservlet?report=blah&keymap=blah to run the reports. The keymap specifies the userid and the other relevant information (destype=CACHE, desformat=PDF, etc)
    The problem is that we are storing information in the HttpSession and many times, but not 100% of the time, once we open the rwservlet results (PDF) into a frame and try to go "back" to our application, the data in HttpSession is gone. It's not 100% of the time, but when using the http://mysrv:7777 for all the URLS to go to apache directly, it happens nearly 100% of the time. When getting the webcache involved it happens much much less.
    I'm wondering if it's because I'm "leaving" my context-root (i.e. going from http://myserv/myapp to http://myserv/reports/rwservlet or something else
    If anyone has experienced this or has a better definition, I'd be happy to hear it.
    Also, if there were a way to include the rwservlet "inside" my application so that I'm not "jumping out" of my application, that would be good to try.
    Thanks for any ideas!
    Regards,
    Jeff

    Hi,
    I am using rwservlet from my JSP without problem. I am using 2 jsp pages. First copy output from rwservlet to the local file (report server is on other machine and I need archive of reports) and in second jsp I send this pdf file to the user directly from JSP.
    first.jsp include:
    <BODY onLoad="window.open("second.jsp?report="+<%=finame%>,...);">
    String sestavaURL="http://host:port/rwservlet?..";
    URL sestava=new URL(sestavaURL);
    HttpURLConnection uc=(HttpURLConnection)sestava.openConnection();
    uc.connect();
    InputStream is=uc.getInputStream();
    //is = Input stream with "cached" PDF report
    FileOutputStream os=new FileOutputStream(finame);
    //os= filename in report archive on localhost
    byte[] buff=new byte[1000];
    int readChars;
    while((readChars=is.read(buff))!=-1)
    os.write(buff,0,readChars);
    and the second.jsp includes:
    <%@page import="java.util.*,java.net.*,java.io.*,oracle.jbo.*,oracle.jbo.html.*,oracle.jbo.server.DBTransaction,java.sql.*"%><%@taglib uri="/webapp/DataTags.tld" prefix="jbo"%><%
    %>
    <%@ page contentType="text/html;charset=ISO-8859-2" errorPage="errorpage.jsp" %><%
    String fileName=finame;
    FileInputStream is;
    try
    is=new FileInputStream(fileName);
    catch(Exception e)
    response.setContentType("text/html");
    out.write("<HTML><BODY><H1>Report was not found</H1></BODY></HTML>");
    return;
    byte[] buff=new byte[1024];
    int readChars;
    response.resetBuffer();
    response.setContentType("application/pdf");
    response.setHeader("Content-disposition","inline;filename=generated.pdf");
    while((readChars=is.read(buff))!=-1)
    out.write(new String(buff),0,readChars); %>
    I hope this help you.
    Best regards
    Lubomir Sterba

  • Can I log out of icloud without losing information and pictures?

    Can I log out of Icloud without losing pictures and info?

    Back them up, sign out, Restore them. They will be deleted (from your computer, but not from your iCloud account) when you sign out.

  • Reinstalling itunes and not losing information about my music

    I getting ready to reformat my hard drive and all of my music is backed up on an external hard drive. I am concerned that when i reinstall itunes on my "clean" hard drive and import all of my music, i will lose data- specifically "date added" . Is there any way to insure that I will not lose this information when i reload??
    dell 8400   Windows XP Pro  

    Copy the iTunes folder from where it is now and replace it/put it back where it is now after you reformat.

  • Restoring ipod and not losing information.

    My ipod died and so i plugged it in. when i took it out the screen said to connect to itunes. so i connected it to my computer and it says to restore my ipod. can i do that without losing any of my music or apps?

    http://www.apple.com/support/ipodtouch/
    http://support.apple.com/kb/HT1414
    The manual and the article above will tell you about restore.
    Your music and apps should be on your computer. You can sync them back.

Maybe you are looking for