简体   繁体   English

如何根据用户输入检查Amazon S3云存储中文本文件存储中的单词?

[英]how to check for word in text file store in amazon s3 cloud storage against user input?

我如何匹配存储在亚马逊S3云存储中的文本文件中的单词,使其与搜索栏中的用户输入不匹配,然后下载特定文件?

Your files in Amazon S3 can be made public and then accessed using HttpURLConnection, as in: 可以将您在Amazon S3中的文件公开,然后使用HttpURLConnection进行访问,如下所示:

    import java.io.*;
    import java.net.HttpURLConnection;
    import java.net.URL;

    class Download
     {public static void main (String args[])
       {String u = "http://s3.amazonaws.com/Bucket/path/file.data";
        String d = download(u);
        System.err.println("Download "+u+"=\n"+d);
       }

      public static String download(String u)
       {final int B = 1024*1024; 

        try 
         {final URL url = new URL(u);
          final HttpURLConnection c = (HttpURLConnection)url.openConnection();
          c.connect();
          final int r = c.getResponseCode(); 
          if (r != 200) 
           {System.err.println("Got response code "+r+", expected 200, cannot download "+u);
            return null;
           }
          System.err.println("Content length="+c.getContentLength());

          final InputStream i = new BufferedInputStream(url.openStream(), B);
          final byte data[] = new byte[B];
          String o = "";

          for(int n = i.read(data); n != -1; n = i.read(data))
           {o += new String(data, 0, n);
           }

          i.close();
          return o;
         }
        catch (Exception e) 
         {System.err.println("Cannot download "+u+" due to "+e);
         }
        return null;
       }
     }

If you are unable to make these files public you will have to go the more complex route of using Amazon IAM to create a user, assign the user privileges, generate a key/secret combination and then use the Amazon AWS SDK for Java documented at http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html . 如果您无法公开这些文件,则必须走更复杂的路线:使用Amazon IAM创建用户,分配用户权限,生成密钥/秘密组合,然后使用http://www.microsoft.com/developerworks/cn/docs ://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html Please post back here if you need help with that route. 如果您需要有关该路线的帮助,请发回此处。

checkout cloudbash.sh-不仅是grep,还包括用于在S3上存储数据的任何Linux工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM