Estoy probando con el siguiente código para descargar varios xml desde un ftp. El primer xml lo descarga correctamente pero a partir del segundo devuelve null
. ¿Cuál sería la forma correcta de hacer esto?
private Vector<InputStream> descargarContenido() {
FTPClient mFTPClient = new FTPClient();
Vector<InputStream> inputstreams = new Vector<InputStream>();
try {
mFTPClient.connect("ftp");
mFTPClient.login("usuario","password");
mFTPClient.enterLocalPassiveMode();
mFTPClient.changeWorkingDirectory("/carpeta/xml");
InputStream input1 = mFTPClient.retrieveFileStream("1.xml");
inputstreams.add(input1);
InputStream input2 = mFTPClient.retrieveFileStream("2.xml");
inputstreams.add(input2);
InputStream input3 = mFTPClient.retrieveFileStream("3.xml");
inputstreams.add(input3);
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error al descargar datos", Toast.LENGTH_LONG).show();
}
return inputstreams;
}
Edición:
He intentado usar el código propuesto por @Ajeno pero obtengo un error al leer el segundo xml, el primero me carga el flujo pero el segundo obtengo este error:
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:299) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) at java.util.concurrent.FutureTask.setException(FutureTask.java:219) at java.util.concurrent.FutureTask.run(FutureTask.java:239) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856) Caused by: java.lang.NullPointerException at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2146) at org.apache.commons.io.IOUtils.copy(IOUtils.java:2102) at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2123) at org.apache.commons.io.IOUtils.copy(IOUtils.java:2078) at MainActivity.descargarContenido(MainActivity.java:544) at MainActivity.parsearXmlDeFTP(MainActivity.java:292) at MainActivity.access$1000(MainActivity.java:32) at MainActivity$TareaDescargaXml.doInBackground(MainActivity.java:228) at MainActivity$TareaDescargaXml.doInBackground(MainActivity.java:222) at android.os.AsyncTask$2.call(AsyncTask.java:287) at java.util.concurrent.FutureTask.run(FutureTask.java:234) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856) E/WindowManager: Activity MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{53459c08 V.E..... R......D 0,0-1026,486} that was originally added here android.view.WindowLeaked: Activity MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{53459c08 V.E..... R......D 0,0-1026,486} that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:354) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) at android.app.Dialog.show(Dialog.java:281) at android.app.ProgressDialog.show(ProgressDialog.java:116) at android.app.ProgressDialog.show(ProgressDialog.java:104) at MainActivity.mostrarbarra(MainActivity.java:202) at MainActivity.access$100(MainActivity.java:32) at MainActivity$6.onClick(MainActivity.java:174) at android.view.View.performClick(View.java:4204) at android.view.View$PerformClick.run(View.java:17355) at android.os.Handler.handleCallback(Handler.java:725) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method)E/EGL_genymotion: egl: current context mark for deletion