我正在使用org.apache.commons.net.ftp.FTPClient并且看到的行为很好......令人费解.
下面的方法打算通过FTP文件列表,读取它们然后对内容做一些事情.这一切都奏效了.什么不是(真的)工作是FTPClient对象执行以下操作...
1) Properly retrieves and stores the FIRST file in the list
2) List item evaluates to NULL for x number of successive iterations of the loop (x varies on successive attempts
3) manages to retrieve exactly 1 more file in the list
4) reports that it is null for exactly 1 more file in the list
5) hangs indefinitely, reporting no further activity.
public static String mergeXMLFiles(List<FTPFile> files, String rootElementNodeName, FTPClient ftp){
String ret = null;
String fileAsString …Run Code Online (Sandbox Code Playgroud) 我使用公共FTPCLIENT我只想要来自ftp服务器的文件内容.我不想把它写入临时文件.有没有办法做到这一点.fileoutputstream应始终指向本地文件.
提前致谢.
我使用Jersey 1.4,ApacheHttpClient和Apache MultiThreadedHttpConnectionManager类来管理连接.为此HttpConnectionManager,我将staleCheckingEnabled设置为true,将maxConnectionsPerHost设置为1000,将maxTotalConnections设置为1000.其他所有内容都是默认值.我们在Tomcat中运行并使用Jersey客户端连接到多个外部主机.
我注意到,经过一段时间后,我将开始看到处于CLOSE_WAIT状态的套接字与Tomcat进程相关联.使用tcpdump进行的一些监视显示外部主机在一段时间后似乎正在关闭连接,但它并没有在我们结束时关闭.通常在套接字读取队列中有一些数据,通常是24个字节.连接使用https,数据似乎是加密的,所以我不确定它是什么.
我已经检查过以确保创建的ClientRequest对象已关闭.CLOSE_WAIT中的套接字似乎确实被回收了,至少在这个时候我们没有耗尽任何资源.我不确定外部服务器上发生了什么.
我的问题是,这是正常的,我应该担心吗?
谢谢,
约翰
我有一个简单的FTPClient类,可以从FTP服务器下载文件.我还需要监控下载的进度,但我没有看到怎样的方式.实际下载文件功能是一个简单的功能
(your ftp client name).retrieveFile(arg1,arg2);
如何监控下载进度?
谢谢,Anon.
尝试byte[]使用org.apache.commons.codec.binary.Base64.. 转换为base64字符串.
对于这个我的java代码看起来像:
base64String = Base64.encodeBase64URLSafeString(myByteArray);
Run Code Online (Sandbox Code Playgroud)
但我看到的是生成的base64字符串中的一些无效字符..
为什么我____在生成的base64String中看到这些行?它是一个有效的字符串吗?请注意,生成的字符串的长度可以分为四个.
我被困在转换Java Bean中Map.互联网上有很多资源,但不幸的是,它们都将简单的bean转换为地图.我的那些更广泛.
有简化的例子:
public class MyBean {
private String firstName;
private String lastName;
private MyHomeAddress homeAddress;
private int age;
// getters & setters
}
Run Code Online (Sandbox Code Playgroud)
我的观点是生产Map<String, Object>哪种,在这种情况下,对于以下条件是正确的:
map.containsKey("firstName")
map.containsKey("lastName")
map.containsKey("homeAddress.street") // street is String
map.containsKey("homeAddress.number") // number is int
map.containsKey("homeAddress.city") // city is String
map.containsKey("homeAddress.zipcode") // zipcode is String
map.containsKey("age")
Run Code Online (Sandbox Code Playgroud)
我试过用Apache Commons BeanUtils.这两种方法BeanUtils#describe(Object),并BeanMap(Object)产生一个地图,"深层次"为1(我的意思是这里只有"homeAddress"钥匙,拿着MyHomeAddress对象的值).我的方法应该越来越深入地进入对象,直到它遇到基本类型(或字符串),然后它应该停止挖掘和插入键即"order.customer.contactInfo.home".
所以,我的问题是:如何轻松完成(或者是否已经存在允许我这样做的项目)?
更新
我已经扩展了Radiodef的答案,还包括Collections,Maps Arrays和Enums:
private static boolean isValue(Object value) { …Run Code Online (Sandbox Code Playgroud) 我可以使用以下方法创建2个互斥选项:
Option a = OptionBuilder.create("a");
Option b = OptionBuilder.create("b");
OptionGroup optgrp = new OptionGroup();
optgrp .setRequired(true);
optgrp .addOption(a);
optgrp .addOption(b);
Run Code Online (Sandbox Code Playgroud)
以上将迫使用户提供选项a或选项b.
但如果我有第三种选择,c:
Option c = OptionBuilder.create("c");
Run Code Online (Sandbox Code Playgroud)
是否可以创建互斥选项,以便:
或者:
我看不到使用OptionGroup的方法吗?
我想使用log4j2 Commons Logging Bridge with commons 1.2.我尝试使用如下内容:
import org.apache.logging.log4j.jcl.LogFactoryImpl;
public class MyClass{
private static Log log = LogFactoryImpl.getLog(DropinsBundleDeployer.class);
.
.
.
log.error("Error occured", e);
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行代码时,我遇到了问题并且看不到任何日志:
log4j:WARN Please initialize the log4j system properly.
Run Code Online (Sandbox Code Playgroud)
但是log4j2.xml文件位于类路径中.如何使用log4j2正确使用commons logging 1.2?
为了获得包含在一个指定的目录,并根据一些扩展的所有文件,我使用的方法listFiles类的FileUtils从阿帕奇百科全书IO库,如下面的代码样本.
ArrayList<String> wildcards = new ArrayList<>();
wildcards.add("*.cpp");
wildcards.add("*.h");
wildcards.add("*.txt");
File dir = new File("/path/to/dir");
Collection<File> found = FileUtils.listFiles(
dir,
new WildcardFileFilter(wildcards, IOCase.SENSITIVE),
DirectoryFileFilter.DIRECTORY);
List<File> files = new ArrayList<>(found);
Run Code Online (Sandbox Code Playgroud)
结果中的项目顺序Collection<File>在不同的操作系统中有所不同,因此我会files根据以下规则对它们(即包装列表)进行排序.
例:
/path/to/dir/first/subpath/main.cpp
/path/to/dir/first/subpath/utils.cpp
/path/to/dir/first/subpath/utils.h
/path/to/dir/first/main.cpp
/path/to/dir/first/utils.cpp
/path/to/dir/first/utils.h
/path/to/dir/second/main.cpp
/path/to/dir/second/utils.cpp
/path/to/dir/second/utils.h
/path/to/dir/README.txt
Run Code Online (Sandbox Code Playgroud) 标题说明一切,找出集合是否包含其他集合的任何元素的最佳实践是什么?
在java中我会像这样执行它
CollectionUtils.containsAny(a, b)
Run Code Online (Sandbox Code Playgroud)
使用常见的apache collection utils,其中变量a/b是集合.
如何在scala中实现此行为?或者是否有像上面的CollectionUtils这样的库?
我不想使用common-apache库,因为我必须将scala集合转换为java集合.
apache-commons ×10
java ×10
ftp ×3
algorithm ×1
base64 ×1
collections ×1
comparator ×1
download ×1
ftp-client ×1
httpclient ×1
javabeans ×1
jersey ×1
log4j ×1
log4j2 ×1
logging ×1
scala ×1
sorting ×1