Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B1AF4200B76 for ; Tue, 30 Aug 2016 16:24:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B00D9160ABA; Tue, 30 Aug 2016 14:24:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CE61A160AA8 for ; Tue, 30 Aug 2016 16:24:06 +0200 (CEST) Received: (qmail 79580 invoked by uid 500); 30 Aug 2016 14:24:01 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 79554 invoked by uid 99); 30 Aug 2016 14:24:00 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Aug 2016 14:24:00 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 7B4991A08EE for ; Tue, 30 Aug 2016 14:24:00 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id goUU4QjuMF6v for ; Tue, 30 Aug 2016 14:23:57 +0000 (UTC) Received: from mail-it0-f52.google.com (mail-it0-f52.google.com [209.85.214.52]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id CEEAC5F36A for ; Tue, 30 Aug 2016 14:23:56 +0000 (UTC) Received: by mail-it0-f52.google.com with SMTP id n75so2820977ith.0 for ; Tue, 30 Aug 2016 07:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=rWZVf5QjccVqQ7u1RD88Rn9F0eLVdYtDHFNQdZa0K8s=; b=eyxtSVo/Nz+tN90CtW9rtDn+lV7K6FyMkD982vzQjFO287x7AkpWyd5jyzI6IM3dDj 1jYX+E1C3duAHqjM7yPIsZ9rDDxbGr1IkhcxDrGztFO3tZY5RLgh7sPqTR+AMOL9/ZIu Roo9hH4dOvdAjl4mHdGVf5FqcRkZKKEKFmfNXt6aMwUivPLVKfQ8o0SSsyxgN2ErMXUd SpmLb1sQQbiofg5KYlH9Akj8jepXz8YxAB5+hAOVDTV7y8GvMAxo/4wvbRfGr574Y1nO YW6m6iKGvC/1BCr5W5x2vfSB/mUJ2sKjyxsdewzXeRcuOi5GA+kvX4Sy/0aFlK1qBGu2 bBng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=rWZVf5QjccVqQ7u1RD88Rn9F0eLVdYtDHFNQdZa0K8s=; b=JFoE/dp/64zidIw26utf3SzwVDWwgiGP9MwUW8nHa0J5r6Ry5SFLkqtT9Dxmdr3bnJ n8028Tx9gf98cH3+5HPP+8KIEjoN+RKnAWAjWgnPZhLjGDOcFoArNjSJknWfCvjEWUzN LguqjS7/yqig5B4zdesueV9HY+qS7CayMosnYiMR6BNV9UjXjiNtvC2c5TLhVUodu0jO HWMtLBUDy/p4W2WpaDWNRlugX9WuQN2y7PRRDQZaM2Wgobma7V1DSoYysfgOaVb11rp5 HmR5iGrm/np2H/Bjjd1wNa3XXBTdZAfxbZ+gNc51u/T/t7+UA5CBFHn/HKEwWPPJFmw0 S5zA== X-Gm-Message-State: AE9vXwOOzrC0Eme5cKBmwf9uYIyQl+ILoiGlFDl1kCFFgmmiY7gG+vjHnYgop6U3jEVigFaDYAnO+T8+ECGl0g== X-Received: by 10.36.190.197 with SMTP id i188mr4273161itf.92.1472567036043; Tue, 30 Aug 2016 07:23:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.181.133 with HTTP; Tue, 30 Aug 2016 07:23:55 -0700 (PDT) In-Reply-To: <392299a8-ef09-8591-2010-184821c622a6@gmail.com> References: <52997869-39df-2a17-9256-bcba68e2f1f4@gmail.com> <20160828200646.00006e32.ecki@zusammenkunft.net> <392299a8-ef09-8591-2010-184821c622a6@gmail.com> From: sebb Date: Tue, 30 Aug 2016 15:23:55 +0100 Message-ID: Subject: Re: NPE in getRemoteAdress To: Commons Users List Content-Type: text/plain; charset=UTF-8 archived-at: Tue, 30 Aug 2016 14:24:07 -0000 On 29 August 2016 at 18:28, Oliver Zemann wrote: > My download method looks like this: > > private void downloadDirectory(FTPClient client, String sourceDir, String > destDir, > ScheduledExecutorService > scheduledExecutorService) throws IOException { > > final FTPFile[] ftpFiles = client.listFiles(sourceDir); > for (final FTPFile ftpFile : ftpFiles) { > > //skip . and .. > if (ftpFile.isDirectory() && (ftpFile.getName().equals(".") || > ftpFile.getName().equals(".."))) { > continue; > } > > if (ftpFile.isDirectory()) { > downloadDirectory(client, sourceDir + ftpFile.getName(), > destDir + "/" + ftpFile.getName(), scheduledExecutorService); > } else { > // scheduledExecutorService.submit(new > DownloadRunnable(destDir, ftpFile, sourceDir, client)); > FileOutputStream fos = new > FileOutputStream(ftpFile.getName()); > client.retrieveFile(sourceDir + ftpFile.getName(), fos ); > fos.flush(); > fos.close(); > } > } > } > > When i run it like this, it works and it downloads the files. But when i use > the scheduledExecuterService, it fails. > So i replaced the 2 lines with my download method (where it uses the > inputstream) to see what happens: > > } else { > // scheduledExecutorService.submit(new > DownloadRunnable(destDir, ftpFile, sourceDir, client)); > new File(destDir).mkdirs(); > final File outFile = new File(destDir, ftpFile.getName()); > final FileOutputStream fos = new FileOutputStream(outFile); > final InputStream inputStream = > client.retrieveFileStream(sourceDir + ftpFile.getName()); > > byte[] buffer = new byte[8096]; > int len = -1; > try { > len = inputStream.read(buffer, 0, buffer.length); > } catch (Exception ex) { > ex.printStackTrace(); > } > while (len != -1) { > fos.write(buffer, 0, len); > len = inputStream.read(buffer); > if (Thread.interrupted()) { > throw new InterruptedException(); > } > } > client.completePendingCommand(); > // informListenersWeFinishedOneFile(sourceDir + > ftpFile.getName(), bytesWritten); > fos.flush(); > fos.close(); > } > } > > That works too?! > > I will go deeper into that at weekend and check whats going on, but at the > moment i really dont understand it. Maybe some kind of concurrency problem > with FTPClient? That seems the most likely. FTPClient is not guaranteed to be thread-safe. I'm not sure that the java.io classes such as InputStream are thread safe either. > > Am 29.08.2016 um 01:40 schrieb Martin Gainty: >> >> possible timeout waiting for FTP to reply >> examples.ftp.FTPClientExample says to increase FTP reply timeout with -w >> parameter >> if (args[base].equals("-w")) { >> controlKeepAliveReplyTimeout = Integer.parseInt(args[++base]); } >> or with FTPClient:ftpClient.setControlKeepAliveReplyTimeout(2000); //2 sec >> reply timeout >> ? >> Martin >> ______________________________________________ >> >> >> >>> Date: Sun, 28 Aug 2016 20:06:46 +0200 >>> From: ecki@zusammenkunft.net >>> To: user@commons.apache.org >>> CC: oliver.zemann@gmail.com >>> Subject: Re: NPE in getRemoteAdress >>> >>> Hello, >>> >>> I am not sure about your NPE, but this code here ignores the result of >>> the read call. It cannot deal with short reads: >>> >>> Am Sun, 28 Aug 2016 >>> 15:50:36 +0200 schrieb Oliver Zemann : >>>> >>>> byte b[] =new byte[4096]; >>>> while (inputStream.read(b) != -1) { >>>> fos.write(b); >>>> bytesWritten += b.length; >>> >>> >>> Gruss >>> Bernd >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org >>> For additional commands, e-mail: user-help@commons.apache.org >>> >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org