FTP(ApacheCommons)ObjectInputStream抛出EOFException

时间:2013-12-07 06:29:28

标签: android ftp apache-commons objectinputstream

这是代码。

    Client.changeWorkingDirectory("./Users");
    Client.changeWorkingDirectory("Users");
    Client.changeWorkingDirectory(UsernameString);
    Client.changeWorkingDirectory("ActiveSells");
    Client.setBufferSize(1024*1024);
    Object earray[] = new Object[5];      //In my code earray is actually something
    Out = new ByteArrayOutputStream(); 
    OOS = new ObjectOutputStream(Out);
    OOS.writeObject(earray);
    RetrievedItem = Out.toByteArray();         //RetrievedItem is a ByteArray
    System.out.println(RetrievedItem.length);  //This tells me 401257
    OOS.flush();
    OOS.close();
    OOS = new ObjectOutputStream(Client.storeFileStream(((String)array[0]).toString()));
    OOS.writeObject(RetrievedItem);
    OOS.flush();
    OOS.close();
    Client.completePendingCommand();
    System.out.println("GetResponse");
    String response = Client.getReplyString();
    System.out.println(response);
    InputStream FIS = Client.retrieveFileStream(((String)array[0]).toString());
    String response2 = Client.getReplyString();
    System.out.println(response2);  //This tells me 390.7kb to download
    OIS = new ObjectInputStream(FIS);
    RetrievedItem = ((byte[])OIS.readObject());  //Gives me EOF
    System.out.println(RetrievedItem.toString());  //From here down the code is skipped
    In = new ByteArrayInputStream(RetrievedItem);  
    OIS = new ObjectInputStream(In);
    Object retrievedfinally = OIS.readObject();
    System.out.println(retrievedfinally);
    In.close();


    return FragMan;

服务器上文件的大小为391kb。我不确定问题是上传对象还是下载对象。任何人都有任何关于为什么会出现故障的建议?

这是错误

12-07 01:12:19.581: W/System.err(20719): java.io.EOFException
12-07 01:12:19.589: W/System.err(20719):    at    libcore.io.Streams.readFully(Streams.java:83)
12-07 01:12:19.589: W/System.err(20719):    at java.io.DataInputStream.readFully(DataInputStream.java:120)
12-07 01:12:19.589: W/System.err(20719):    at java.io.ObjectInputStream.readNewArray(ObjectInputStream.java:1473)
12-07 01:12:19.589: W/System.err(20719):    at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:785)
12-07 01:12:19.589: W/System.err(20719):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2006)
12-07 01:12:19.589: W/System.err(20719):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1963)
12-07 01:12:19.589: W/System.err(20719):    at com.blablaba.NetAsyncTask.NewSellItemUpload(NetAsyncTask.java:309)
12-07 01:12:19.589: W/System.err(20719):    at com.blablabla.NetAsyncTask.UploadFile(NetAsyncTask.java:203)
12-07 01:12:19.589: W/System.err(20719):    at com.blablabla.NetAsyncTask.doInBackground(NetAsyncTask.java:112)
12-07 01:12:19.589: W/System.err(20719):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-07 01:12:19.589: W/System.err(20719):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-07 01:12:19.589: W/System.err(20719):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-07 01:12:19.589: W/System.err(20719):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-07 01:12:19.589: W/System.err(20719):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-07 01:12:19.589: W/System.err(20719):    at java.lang.Thread.run(Thread.java:856)

1 个答案:

答案 0 :(得分:0)

显然这是一个无法解决的问题。我试图上传的对象是一个对象数组,最后一个对象是一个图像。看起来Apache公共资源中的一个小故障是它不会上传图像的最后一点,从而破坏它。我已经切换到ftp4j,它可以工作。