tags:

views:

51

answers:

1

Hi All,

I am working in an application development. On that application i am performing files store, retrieve and delete operations. For identifying the files on server i am using an index(a hash map file) file. every time when i perform upload operation i update "index" file and upload "index" file on server along with other uploading files.

For performing delete operation first i am retrieving the "index" file and based on the index i am deleting the files from server and after updating "index" file i again upload "index" file on server.

I am able to perform file uploading operation successfully but while performing delete operation, i am getting "java.io.EOFException" exception, when i am trying to retrieve "index" file.

i am writing following code to download "index" file from FTPS server

//download index file
if (service.retrFile("INDEX", "") == service.OK) {
    try {
        ObjectInputStream objIn = new ObjectInputStream(new FileInputStream("INDEX"));
        try {
       Map<String, FileData> filesUploaded = (HashMap<String, FileData>) objIn.readObject();

        } catch (ClassNotFoundException ex) {
           ex.printStackTrace();
        }
        objIn.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

Where "service.ok" returns '0' if it is successfully connected to FTPS server and "FileData" contains information about file(attributes).

Same code i am using while performing uploading operation. there it is working fine with no exception. but while performing delete operation when i am retrieving "index" file i am getting exception on the statement :

Map filesUploaded = (HashMap) objIn.readObject();

Exception is :

SEVERE: null

java.io.EOFException
        at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2298)
        at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2767)
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:798)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:298)
        at com.pixelvault.gui.DeleteServerFilesDialog.startDeleting(DeleteServerFilesDialog.java:447)

I have checked whether FTPS server connections are properly closed after performing corresponding operations.

I am not getting where i am doing wrong.

please give me your valuable suggestions. i thank to all your suggestions which will help me to overcome with this problem.


i am using org.apache.commons.net.ftp and "retrFile" is a method created by me for retrieving files from server.

Here is code for "retrFile"

FTPSClient ftp;

public int retrFile(String filename, String savePath) { if (!connected) { return ERR; }

    FileOutputStream fout = null;
    InputStream bin = null;
    try {
        ftp.enterLocalPassiveMode();
        fout = new FileOutputStream(savePath + filename);
        bin = ftp.retrieveFileStream(filename);
        if (bin == null) {
            fout.close();
            return ERR;
        }
        byte[] b = new byte[ftp.getBufferSize()];
        int bytesRead = 0;
        while ((bytesRead = bin.read(b, 0, b.length)) != -1) {
            fout.write(b, 0, bytesRead);
        }
        ftp.completePendingCommand();
        fout.close();           
    } catch (FTPConnectionClosedException ex) {
         ex.printStackTrace();
        connected = false;
        return NOT_CONNECTED;
    } catch (IOException ex) {
         ex.printStackTrace();
        return ERR;
    } finally {
        try {
            fout.close();
        } catch (IOException ex) {
             ex.printStackTrace();
            return ERR;
        }
        try {
            if (bin != null) {
                bin.close();
            }
        } catch (IOException ex) {
             ex.printStackTrace();

            return ERR;
        }
    }
    return OK;
}
A: 

Are you sure the INDEX file is correctly downloaded?

It's present in the filesystem when application is closed?

What FTP lib are you using?. i only know commons.net from Apache and i not recognice the "retrFile" file method. Could it be threaded so that the file is not completely downloaded when the readObject statement is executed?

Telcontar