Problems transferring multiple files

I'm trying to write a program to transfer multiple files from a client to a server, but I'm having trouble getting the server to distinguish between them.
I have tried both buffered streams, and straight input/output streams, and in both cases, the server doesn't seem to get any EOF, and keeps reading all data it reads into the first file. I can't figure out why EOF is never read (ie: ((read = bis.read(buffer)) != -1) never evaluates to -1). Can anybody see why that might be?
Client:
buffer = new byte[16384];
out    = serverSocket.getOutputStream();
bos    = new BufferedOutputStream(out);
objOut = new ObjectOutputStream(out);
objOut.writeInt(file.length);  // # of files to transfer
for (int i=0; i<file.length; i++) {
    try {
        fileIn = new FileInputStream(file.getAbsolutePath());
objOut.writeLong(file[i].length()); // file length (for dirty CRC check)
objOut.writeObject(file[i].getName()); // file name
objOut.flush(); // because otherwise the server hangs waiting
while ((read = fileIn.read(buffer)) > 0) {
bos.write(buffer, 0, read);
bos.flush();
catch (Exception e) {}
Server:
in = socket.getInputStream();
objIn = new ObjectInputStream(in);
bis = new BufferedInputStream(in);
fileCnt = objIn.readInt();  // # of files to be transferred
for (int i=0; i<fileCnt; i++) {
    totalLen = objIn.readLong();  // file length
    try { fileName = (String)objIn.readObject(); }  // file name
    catch (Exception e) {}
    try { toFile = new FileOutputStream(new File(fileName)); }
    catch (FileNotFoundException ex) {}
    while ((read = bis.read(buffer)) != -1) {
        toFile.write(buffer, 0, read);

the problem is you are not stoping the writing to file when you hit the end of one file.
At the server you should count the number of bytes that you write to the disk and should stop when the total count reach the file size.
Or you have to completly change your protocole to handle entire file as one unit.
Ex:-
public class MyFile implements java.io.Serializable{
String path;
private void writeObject(ObjectOutputStream oos){
   oos.defaultWriteObject();
   byte b[] = new byte[1024*128];
   int i = 0;
   FileInputStream fis = new FileInputStream(path);
   while ((i = fis.read(b)) >=0){
      oos.writeObject(trim(b,i));
   fis.close();
   oos.writeObject("EOF");
private byte[] trim(byte b[], int i){
    byte b2[] = new byte;
System.arraycopy(b,0,b2,0,i);
return b2;
// You should be able to write the read object method

Similar Messages

  • Problems selecting multiple files

    I just replaced my MacBook Pro with a newer version.  I am trying to organize my photos and cannot select multiple files or photos.
    I'm needing to organize in Pictures not iPhoto. 
    I've had Macs for years and never had an issue before.
    Thanks,

    the problem is you are not stoping the writing to file when you hit the end of one file.
    At the server you should count the number of bytes that you write to the disk and should stop when the total count reach the file size.
    Or you have to completly change your protocole to handle entire file as one unit.
    Ex:-
    public class MyFile implements java.io.Serializable{
    String path;
    private void writeObject(ObjectOutputStream oos){
       oos.defaultWriteObject();
       byte b[] = new byte[1024*128];
       int i = 0;
       FileInputStream fis = new FileInputStream(path);
       while ((i = fis.read(b)) >=0){
          oos.writeObject(trim(b,i));
       fis.close();
       oos.writeObject("EOF");
    private byte[] trim(byte b[], int i){
        byte b2[] = new byte;
    System.arraycopy(b,0,b2,0,i);
    return b2;
    // You should be able to write the read object method

  • Lp - problems with multiple files ?

    Does anyone know of or have experienced problems with the lp command and
    multiple files on Solaris 5.6?. Currently when trying to print issuing one lp command for 164 files from within a script i.e lp file1 file2 file3..... file164, a request id is received for the job but then the job just disappears, no error message, nothing !. Any ideas ?

    Thanks for the swift response. Always ideas are useful.
    As of now , Middleware cannot split the file.
    Thing is SAP is creating two Idocs with different message types. Problem is First IDoc contains ORDERS message type but also DELIVERY segments as well. Second IDoc with DELIVERY message tyoe but ORDERS segments as well... This is the problem... I think we are missing some field activation in file for EDIDC record.
    As far as I know file port supports the number of IDocs in one file.. Hope TRFC port also supports that

  • Elements 11, PC Windows 8.  Problem: Process Multiple Files is grayed out.  How can I activate it?

    I have to reduce the resolution for files in a folder.  I have done this in the past but have a problem with the reinstall of Elements 11 on a PC that lost it's mind and had to reinstall all software.  The Process Multiple Files under the File heading is grayed out and will not allow me to point to the files to be reduced.  Sure would like some help on this.   THX.

    You have to be in Expert Mode (see this picture) to enable the "Process Multiple Files ..." from the file menu.   You are in the Editor windows, right?

  • Problem with multiple files download (OD 6.0)

    Please, help me :(
    I have a proble with installation of Developer 6.0 after I
    downloaded multiple files and joined them.
    At command prompt it says "The program is too big to fit in
    memory" or something like it. (623K of conventional memory at
    that time).
    Do you know how to solve this problem. I will appreciate your
    help very much.
    Thank you.
    Leonid Roodnitsky
    null

    Please, help me :(
    I have a proble with installation of Developer 6.0 after I
    downloaded multiple files and joined them.
    At command prompt it says "The program is too big to fit in
    memory" or something like it. (623K of conventional memory at
    that time).
    Do you know how to solve this problem. I will appreciate your
    help very much.
    Thank you.
    Leonid Roodnitsky
    null

  • Transferring multiple files over a single socket

    I'm trying to send multiple files to a client without creating a new socket for each file and I'm undeceided on the best approach. The problem is that if the client is just reading from a socket, it won't know when one file stops and the next begins (assuming that the server side is just writing byte data to the socket). I could use an ObjectStream, but then I can't create a nifty progress bar. I could transfer the byte length of each file so that the client knows how much to read, but this seems messy. Is there a better approach?

    Method 1: send file length first. Simple way. Downside: if the file size changes on disk while you are sending it you may be in trouble - what if the file is truncated or there is an IO error so you can't send as many bytes as you promised.
    Method 2: use an end-of-file indicator. E.g. "." on a line by itself. If the file contains a "." on a line you'll need to quote it - e.g. the SMTP mail protocol uses "..", and "..." for two periods, etc. Needs a bit of extra code to do the quoting and detecting the EOF marker.
    Method 3: send "packets". Send a "packet header" followed by data, e.g.:
    HERECOMES C:\fred.txt
    DATA 1024 <...1024 bytes...>
    DATA 1024 <...1024 bytes...>
    DATA 120 <...last 120 bytes...>
    END OF FILE HAVE A NICE DAY
    You can make the "packet header commands" binary ('\001' = file begins, '\002' = data segment, ...) or sort of human readable like SMTP and HTTP do. The former can be a bit easier to implement, the latter is nice because you can debug it easier and try it out with "telnet".

  • Problems importing multiple files into iTunes

    I'm running the most recent version of iTunes. When I try to add multiple files to my itunes library a box pops up and it seems to be importing, but when the box closes, the files are not in my library. I can only add 2 or three files at a time, but no more than that. This didn't happen with the older version of iTunes. Is anyone else having the same problem, and is there a way to solve this? I have tons of files that I want to import, but at this rate, it will take months to import them. Please help!

    flash is limited to 16,000 frames.
    use several swfs and load them into a main swf.

  • Problem with multiple file download

    Good day.
    I have a code that downloads multiple files from the database and then saves it to a specified directory. I work fine but when I check the contents of the file, some of them are not complete. Lets, say I have downloaded 16 files and only file # 4,5,6,7 have the correct contents as compared to the original.
    Why is that so?
    my code snippet:
    DiskFileUpload fu = new DiskFileUpload();
              fu.setSizeMax(1000000000);
              List fileItems = fu.parseRequest(request);
             Iterator itr = fileItems.iterator();
              while(itr.hasNext())
              FileItem fi = (FileItem)itr.next();
              if(!fi.isFormField())
                     String filen = fi.getName();
                     String fname = filen.substring(filen.lastIndexOf(java.io.File.separator)+1);
                   Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
                   connection = DriverManager.getConnection(connectionURL, "", "");
                   statement = connection.createStatement();
                   String sql = "INSERT INTO tblTestFiles("
                                    + "strFileName,"
                                    + "imgFile) "
                                    + "VALUES(?,?)";
                 PreparedStatement pstmt = connection.prepareStatement(sql);
                   //Set the values for strFileName and imgFile
                   pstmt.setString(1,fname);
                   // Set the blob
                   //File file = new File(fnew);
                 FileInputStream is = new FileInputStream(filen);
                 pstmt.setBinaryStream(2, is, (int)filen.length());
                     // Insert the row
                 pstmt.executeUpdate();I am using eclipse 5.5.23, eclipse 3.2 with myeclipse SDK, MS SQL, Ant.

    sorry I posted the wrong code. here's the correct one:
    statement = connection.createStatement();
            rs = statement.executeQuery("SELECT strFileName,imgFile FROM tblTestFiles ORDER BY strFileName");
            while (rs.next())
                   String filename = rs.getString(1);
                Blob blob = rs.getBlob(2);
                   InputStream is = null;
                   is = blob.getBinaryStream();
                   int i;
                   String dir = "C:\\DownloadedFiles";
                   File path = new File(dir, filename);
                   FileOutputStream fos = null;
                   fos = new FileOutputStream(path, true);
                   PrintWriter pout = null;
                   pout = new PrintWriter(new FileOutputStream(path,true));
                   while ((i = is.read()) != -1)
                      pout.write(i);
                   fos.close();
                   pout.close();
             }// end of if construct
        }// end of try
         catch (IOException e)
             e.getMessage (); e.printStackTrace();
              System.out.println(e);
        catch (SQLException e)
             e.getMessage (); e.printStackTrace();
              System.out.println(e);
        }Thanks.

  • Problem Processing Multiple Files in Photoshop Elements

    I have always used the process multiple files option in the File drop down menu without issue. I recently completed editing some photos as I have done before and wanted to process them into a smaller JPEG file and add my watermark. I set all the settings in the process multiple files program and clicked OK. The first image came up and appeared to process but then a "save as" dialogue box came up. The box was asking to save the file as a photoshop file and not a JPEG. I cant seem to find out why it is doing this. I have restarted the program and my computer running it and I have tried running the same process on other files with the same result.

    Which Elements version ?
    Was it a raw format file ?
    If so, is your bit mode menu in the middle of the bottom bar of the ACR dialog set to 16 bits ? Try setting it to 8 bits and save a raw file in 8 bits before trying the process multiple files again to see if that makes a difference.

  • Zen Touch 40 GB: problems transferring music files and playli

    Hi,
    Creative Zen Touch 40 GB, one year old<
    [color="#330000">PlaysForSure Firmware 2..0<
    Creative MediaSource Organizer 5.0.38<
    Creative?Sync Manager 5.0.9.0<
    Windows XP Service Pack 2<
    527?music (.wma) files on the player; 4205 MB of free space<
    I'm finding it increasingly difficult to?transfer music files and playlists to my Zen Touch player now that the amount of free space on it has fallen below 5 GB. More often than not, it's necessary to put the player into Recovery mode, perform a clean-up, and then reboot and rebuild the library before Sync Manager works properly. I often need to repeat this process several times before I can transfer anything. Increasingly, too, Windows fails to detect the presence of the player when I connect it to my computer. Rebooting both the player and the computer usually fixes this issue. Transferring files by dragging and dropping in Windows Explorer is obviously much quicker than using Sync Manager, but here again I keep running into problems. It's as if the player freezes and refuses to take on-board any more files. Also, I can't find a way to transfer playlists except with Sync Manager. Are these known problems? I recalling running into similar issues with the Zen Touch 20 GB a few years ago. And could the fact that I'm doggedly using an old (998) and underpowered computer be an issue? I'm thinking of replacing the computer anyway, but is it likely that these synchronization problems would diminish or disappear altogether if I were to upgrade to something speedier?Thanks for any insights,Pete

    I too have a simular problems! Managing music is the biggest problem with over 0 Gigs. Some artists songs sometimes change name titles, artists,?and etc. Win Explorer is most used by me now. Yes, I do lose sync from time to time! Especially when I open two windows on the portable zen. There are two tools that need. . Playlist management - it takes too long to do it on the player. I want to create "Gym Vibes" and had it on my old creative?Nomad player, but couldn't transfer. "Creative Sync Manager" doesn't do it!?Without all that sync stuff how can I create and edit creative's playlist on a PC?2. A method for detecting dupicates?This is my second creative portable and if I don't get the tools I won't buy another!

  • PROBLEM  TRANSFERRING   MULTIPLE   DATA  ENTRIES    FOR  ONE KEY-FIELD.

    DEAR   EXPERTS ,
       I  HAVE  TRANSFERRED  DATA  FROM  THE  FINAL  INTERNAL  TABLE  OF  MY  ABAP REPORT (NOT ALV)  TO  CUSTOM  Z-TABLE  CREATED  IN  SE11.
    BUT  MY  PROBLEM  IS  :  I   COULD  NOT   TRANSFER  MULTIPLE   DATA  ENTRIES   FOR  A  PARTICULAR  FIELD.
    FOR  EXAMPLE :  IN  TABLE  EKKO  THERE  ARE   FOUR  EBELN-4900006375  AND  FOR  THAT  DIFFERENT  EBELP S  ARE
    PRESENT.  I  COULD  TRANSFER  ONLY  THE  FIRST  ENTRY ,  THAT  IS :  EBELN -  4900006375  AND   EBELP - 0010,
    AFTER  THAT  THE  ZTABLE  IS  NOT  GETTING  UPDATED  TO  EBELN-4900006375 FOR  EBELP - 0020  AND  SO ON.
    I  HAVE  TRIED  ALL  THE  '  MODIFY, INSERT,  UPDATE  '  STATEMENTS.  I  HAVE  USED  AT - USERCOMMAND - HIDE  AND  CHECKBOXES.
       PLEASE   SUGGEST   A   SAMPLE   CODE   FOR   THIS.
    Moderator message: please post again, but not in all upper case.
    [Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
    Edited by: Thomas Zloch on Jun 19, 2011 10:05 PM

    There are actually 5 queries in this report now. From what I understand about a union query, I don't think it will work here because the data being returned in each of the queries is so different. I basically need to know how to make all the criteria for each individual to be displayed before proceeding to the next data set, which will include the same data as the first, but for the next employee, and so on. I need to basically create a repeating frame with each individual's respective data I guess, but every time I do, it tells me that it's referencing an invalid group.

  • Problem transferring MOV files from SD card

    I have HD video on SDHC cards recorded on the new JVC GY-HM100U. This camera records in a native final cut pro codec that can drag and drop to a hard drive for editing.
    My problem is that I am having an inconsistent experience getting the files from the SD cards to my hard drives. I generally transfer via my express slot with a card reader. Sometimes it works great and other times, my laptop dismounts the drive and I get the following error...
    "The finder cannot complete the operation because some data in " " could not be read or written (error code -36)."
    I have also used a USB card reader with my desktop and that usually works fine as a workaround, but not today. There seems to be no common denominator when the problem occurs.
    Anybody know what my problem is?
    thanks,
    mvw

    Sorry, I did not see some of these responses until now. Unfortunately, I have not used the new camera since these problems. I actually got a new camera to replace the original. I spoke with a guy at JVC regarding some imaging issues I was having and he assured me they were not normal, so I got a new unit.
    Aside from the issues I've had, I find the functionality and the performance of the camera to be excellent. looking forward to putting it through more paces.
    mvw

  • Problem processing multiple files with dll

    I'm using a function in a dll that turns a binary data file into a TSV file with actual numbers.  The function takes three inputs, a pointer to a string for the input file path, a pointer to a string for the file to write and an integer for "integrity check" which as far as I can tell does nothing.  I have the dll in a subvi, pass it a string corresponding to the input file path and let it convert the file.  This works but will only convert the first 254 files then errors out.   The only way I can get it to work again is to close labview completely and reopen it.  My experiment requires the conversion of literally thousands of files so closing and reopening labview gets old real quick.  I have tried creating a reference to the subvi and closing it for each file but this still does not work, I have also tried on windows xp and windows 7.  When the new files are created they have a size of 0 kB and are empty until I close labview then they assume a reasonable size (few kB) and have data in them.  Additionally if I try to delete one of the newly created files while labview is open I get an error saying the file is open in labview.  I can delete the files when labview is closed.  I have also tried opening each file and closing it after the conversion but that does not work either.
    I believe this is some sort of file open limitation but I don't know how to get around it, I'm almost to the point of writing one of those mouse move/button click macros nerds use for games to convert the files because this is driving me insane.

    I managed to get the c code for the dll (it was somewhere on the computer). I can only pass an integer to validity otherwise it errors, is there an unsighed char in labview?
    _declspec (dllexport) int converting(char *filetoRead, char *filetoWrite, unsighed char validity)
    FILE *fpin, *fpout;
    int result;
    int records=0;
    int valid=0;
    unsigned long MTOFL=0;
    unsigned long MT;
    struct {unsigned ADC:12;
    unsigned INVALID
    unsigned MTOV:1;
    unsigned GAP:1;
    unsigned ZERO:1;
    unsigned MTHIGH:
    unsigned R:8;
    unsigned MTLOW:
    } DataRecord;
    fpin=fopen(filetoRead,"rb");
    fpout=fopen(filetoWrite,"w");
    while(1)
    result = fread( &DataRecord,
    if (result!= 6)
    return(0);
    records++;
    if(DataRecord.MTOV)
    MTOFL += (unsign
    if(validity==1)
    if(DataRecord.INVA
    continue; // don't sav
    valid++;
    MT = (((unsigned long)Data
    fprintf(fpout,"%11lu",MTOF
    fprintf(fpout,"%5u",DataRec
    fprintf(fpout,"%4u",DataRec
    fprintf(fpout,"%6u",DataRec
    fprintf(fpout,"\n");
    fclose(fpin);
    fclose(fpout);
    return 0;

  • Problem transferring purchased files from Yahoo Jukebox to I-tunes

    Any ideas here? Do I have to take my I-pod back and buy a zune or some other non-apple mp3 player?
    I bought a significant number of files under Musicmatch--which then switched over to Yahoo--Jukebox. Bought and paid for them.
    I- Tunes refuses to allow transfer of them because it claims they are in some type of protected format.
    I found an old topic here that basically said tough luck...no options.
    If that is the case, I will be bringing back my I-pod for a refund. It's ridiculous...I paid for the music, I didn't steal it. Ought to be some way to transfer it so it's readable within I-Tunes!
    <Edited by Moderator>

    The songs sold by Music Match were WMA files with Microsoft "Plays For Sure" DRM "protection." They cannot be played in iTunes. (BTW, they will not play in the Zune either; it has its own Zune-specific DRM.) All you can do with those files is use Windows Media Player to burn them to an audio CD.

  • Error when transferring Media files from Mac to blackberry

    Hello
    I am having problems transfering media files from my mac to the blackberry pearl 8100. I followed the steps and went into the media file selected "receive by bluetooth" and went to the mac and selected the media file I want to send. The screen open on the mac waiting to connect i select save in ringtones device, get the message on both devices transfer failed. I did all the steps on the support but nothing works. Both devices are paired I can send file from the blackberry to the mac but I cannot receive any media files. I sent pictures from the mac to the blackberry and it worked fine.
    Need some help please. 
    Solved!
    Go to Solution.

    problem resolved. phone needed additional memory...

Maybe you are looking for