小编Unn*_*ris的帖子

最强大的使用Java读取文件或流的方法(防止DoS攻击)

目前我有以下代码供阅读InputStream.我将整个文件存储到StringBuilder变量中,然后处理该字符串.

public static String getContentFromInputStream(InputStream inputStream)
// public static String getContentFromInputStream(InputStream inputStream,
// int maxLineSize, int maxFileSize)
{

    StringBuilder stringBuilder = new StringBuilder();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
    String lineSeparator = System.getProperty("line.separator");
    String fileLine;

    boolean firstLine = true;
    try {
        // Expect some function which checks for line size limit.
        // eg: reading character by character to an char array and checking for
        // linesize in a loop until line feed is encountered.
        // if …
Run Code Online (Sandbox Code Playgroud)

java denial-of-service readline bufferedreader

22
推荐指数
2
解决办法
4万
查看次数

通过JSch进行SSH隧道连接

我的目标是连接到防火墙后面的服务器(主机).我可以通过连接到网络中的另一个服务器(隧道)然后SSH到此服务器来访问此服务器.但是我无法通过JSch实现相同的场景.

我无法使用以下代码工作,我为此目的编写了这些代码.如果我在这里做任何蠢事,请告诉我.

public class JschExecutor {

    public static void main(String[] args){
        JschExecutor t=new JschExecutor();
        try{
            t.go();
        } catch(Exception ex){
            ex.printStackTrace();
        }
    }
    public void go() throws Exception{

        StringBuilder outputBuffer = new StringBuilder();

        String host="xxx.xxx.xxx.xxx"; // The host to be connected finally
        String user="user";
        String password="passwrd";
        int port=22;

        String tunnelRemoteHost="xx.xx.xx.xx"; // The host from where the tunnel is created

        JSch jsch=new JSch();
        Session session=jsch.getSession(user, host, port);
        session.setPassword(password);
        localUserInfo lui=new localUserInfo();
        session.setUserInfo(lui);
        session.setConfig("StrictHostKeyChecking", "no");

        ProxySOCKS5 proxyTunnel = new ProxySOCKS5(tunnelRemoteHost, 22);
        proxyTunnel.setUserPasswd(user, password); …
Run Code Online (Sandbox Code Playgroud)

java ssh jsch ssh-tunnel

10
推荐指数
1
解决办法
1万
查看次数

如何使用JDT以编程方式重命名方法

我的目标是以编程方式调用Refactor >> RenameEclipse命令以获取Java源文件中的方法.重命名方法也应该将更改应用于使用/引用此方法的所有实例.

我相信JDT有一个Refactoring API,但是无法找到相同的文档或教程.

有人能指出我正确的方向.

编辑:运行时不需要更改.

java refactoring abstract-syntax-tree eclipse-jdt

7
推荐指数
1
解决办法
1593
查看次数

Android使用MultipartEntity将图像发布到服务器

我一直在尝试将图像和数据上传到Django服务器.我已经包含apache-mime4j.0.6.jarhttpmime4.0.1.jar库(项目 - >构建路径 - >添加外部jar文件)这里是上传图像的代码.

HttpResponse response = null;
try {
    HttpPost httppost = new HttpPost("http://10.0.2.2:8000/mobile");
    //  HttpPost httppost = new HttpPost("some url");

    MultipartEntity multipartEntity = new MultipartEntity(); //MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);  
    multipartEntity.addPart("name", new StringBody("nameText"));
    multipartEntity.addPart("place", new StringBody("placeText"));
    multipartEntity.addPart("tag", new StringBody("tagText"));
    //multipartEntity.addPart("Description", new StringBody(Settings.SHARE.TEXT));
    multipartEntity.addPart("Image", new FileBody(destination));
    httppost.setEntity(multipartEntity);

    httpclient.execute(httppost, new PhotoUploadResponseHandler());

  } catch (Exception e) {
    Log.e( "Error","error");
  } 
Run Code Online (Sandbox Code Playgroud)

错误信息:

Could not find class 'org.apache.http.entity.mime.MultipartEntity'
Run Code Online (Sandbox Code Playgroud)

我尝试手动创建libs文件夹并手动将jar文件包含到/ libs文件夹中.当我这样做它无法编译.

错误:

Conversion to Dalvik format failed …
Run Code Online (Sandbox Code Playgroud)

django android dalvik multipartentity

6
推荐指数
1
解决办法
1万
查看次数

如何查找IType是否为抽象类

我有一个类的IType对象.我想知道这个类是否是一个抽象类.IType或ICompilationUnit中是否有任何方法可用于确定相同的方法(反射除外).

java eclipse-jdt

6
推荐指数
2
解决办法
1228
查看次数

如何将Swing组件添加到SWT?

我想在JTree我的代码中添加一个Swing组件(),它使用SWT.
有什么方法可以实现这个目标吗?
我知道我们TreeViewer在SWT/Jface中有组件,但我已经开发了一个Jtree实现,并希望添加它,而不是使用TreeViewer重写.

java swing swt eclipse-rcp

6
推荐指数
1
解决办法
1955
查看次数

curl:(35) 错误:140770FC:SSL 例程:SSL23_GET_SERVER_HELLO:未知协议

我正在尝试连接配置为使用 ssl 的远程 nginx 服务器。

我发出了一个命令

$curl  https://10.73.80.197:8080/ 
Run Code Online (Sandbox Code Playgroud)

但在那之后我收到错误。这是整个日志-

* Hostname was NOT found in DNS cache
*   Trying 10.73.80.197...
* Connected to 10.73.80.197 (10.73.80.197) port 80 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Closing connection 0
curl: (35) error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Run Code Online (Sandbox Code Playgroud)

ssl https curl

6
推荐指数
1
解决办法
2万
查看次数

查看删除的控制台输出

我正在运行多个Junit测试,在控制台中运行测试结果被清除并填充当前测试的日志.将存储包含先前测试日志的日志文件.在eclipse中有没有办法,通过它我可以看到这样的删除日志.

java eclipse console

5
推荐指数
1
解决办法
1876
查看次数

Eclipse从.java文件创建CompilationUnit

如何将.java文件加载到CompilationUnit中?例如,假设我当前项目中有一个A.java文件.我想将它加载到CompilationUnit中,然后将其传递给ASTParser.只是将它作为纯文本加载它不是一个选项,因为在这种情况下我似乎不会获得AST中的绑定信息.

java eclipse abstract-syntax-tree compilationunit eclipse-jdt

5
推荐指数
1
解决办法
4676
查看次数

FieldDeclaration到IField - 从FieldDeclaration获取IBinding

如何将FieldDeclaration(type:ASTNode)转换为IField(type:JavaElement).是否可以从FieldDeclaration ASTNode获取绑定,就像node.resolveBinding()和MethodDeclaration节点一样.

需要:我正在访问具有公共常量的类中的FieldDeclaration节点,并且想要在项目中搜索该字段的引用.我正在使用JDT的SearchEngine.为此,我想创建一个搜索模式,如下所示:

SearchPattern.createPattern(iField, IJavaSearchConstants.REFERENCES);
Run Code Online (Sandbox Code Playgroud)

我已将此问作为对我的一个问题的评论,但没有得到相同的答案.将其作为单独的问题发布.

在此先感谢您的回答.


回答Deepak的回答.

使用您的方法,我可以检索JavaElement,如下所示

List<VariableDeclarationFragment> fragments = node.fragments();
VariableDeclarationFragment fragment = fragments.get(0);
IJavaElement fieldElement = fragment.resolveBinding().getJavaElement();
Run Code Online (Sandbox Code Playgroud)

如果我传递此IJavaElement来创建搜索模式而不是IField,它将返回与IField相同的结果.

java abstract-syntax-tree eclipse-jdt

4
推荐指数
1
解决办法
717
查看次数