private List<byte[]> descargarContenido() {
FTPClient mFTPClient = new FTPClient();
List<byte[]> inputstreams = new ArrayList<byte[]>();
try {
mFTPClient.connect("ftp");
mFTPClient.login("usuario","password");
mFTPClient.enterLocalPassiveMode();
mFTPClient.changeWorkingDirectory("/carpeta/xml");
InputStream input1 = mFTPClient.retrieveFileStream("1.xml");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(input1,baos);
input1.flush();
input1inputstreams.closeadd(baos.toByteArray());
inputstreams.add(baos.toByteArrayclose());
InputStream input2 = mFTPClient.retrieveFileStream("2.xml");
baos = new ByteArrayOutputStream();
IOUtils.copy(input2,baos);
input1input2.flush();
input1inputstreams.closeadd(baos.toByteArray());
inputstreams.add(baos.toByteArrayclose());
InputStream input3 = mFTPClient.retrieveFileStream("3.xml");
baos = new ByteArrayOutputStream();
IOUtils.copy(input3,baos);
input1input3.flush();
input1inputstreams.closeadd(baos.toByteArray());
inputstreams.add(baos.toByteArrayclose());
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error al descargar datos", Toast.LENGTH_LONG).show();
}
return inputstreams;
}
https://commons.apache.org/proper/commons-io/
No sé si es el lugar adecuado pero añado el trace aquí.
si, 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 weag.checkenerconv2.MainActivity.descargarContenido(MainActivity.java:544)
at weag.checkenerconv2.MainActivity.parsearXmlDeFTP(MainActivity.java:292)
at weag.checkenerconv2.MainActivity.access$1000(MainActivity.java:32)
at weag.checkenerconv2.MainActivity$TareaDescargaXml.doInBackground(MainActivity.java:228)
at weag.checkenerconv2.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 weag.checkenerconv2.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 weag.checkenerconv2.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 weag.checkenerconv2.MainActivity.mostrarbarra(MainActivity.java:202)
at weag.checkenerconv2.MainActivity.access$100(MainActivity.java:32)
at weag.checkenerconv2.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