小编Aug*_*ani的帖子

JAVA - 从Webserver下载二进制文件(例如PDF)文件

我需要从网络服务器下载pdf文件到我的电脑并在本地保存.

我使用Httpclient连接到webserver并获取内容正文:

HttpEntity entity=response.getEntity();
                InputStream in=entity.getContent();

                String stream = CharStreams.toString(new InputStreamReader(in));
                int size=stream.length();
                System.out.println("stringa html page LENGTH:"+stream.length());
                 System.out.println(stream);
                 SaveToFile(stream);
Run Code Online (Sandbox Code Playgroud)

然后我将内容保存在文件中:

                              //check CRLF (i don't know if i need to to this)
                                   String[] fix=stream.split("\r\n");

                                      File file=new              File("C:\\Users\\augusto\\Desktop\\progetti web\\test\\test2.pdf");
                                      PrintWriter out = new PrintWriter(new FileWriter(file));
                                      for (int i = 0; i < fix.length; i++)  {
                                          out.print(fix[i]);
                                         out.print("\n");

                                      }
                                     out.close();
Run Code Online (Sandbox Code Playgroud)

我还尝试将String内容直接保存到文件:

                         OutputStream out=new FileOutputStream("pathPdfFile");
                         out.write(stream.getBytes());
                         out.close();
Run Code Online (Sandbox Code Playgroud)

但结果总是一样的:我可以打开pdf文件,但我只能看到白页.错误是围绕pdf流和endstream charset编码吗?stream和endStream之间的pdf内容是否需要以其他方式进行操作?


希望这有助于避免对我想做的事情产生一些误解:

这是我的登录(完美地工作):

  public static void postForm(){
    String cookie="";
    try {
   System.out.println("POSTFORM ###################################");
     String postURL = …
Run Code Online (Sandbox Code Playgroud)

java post login httpclient

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

C - 如何使用PROGMEM存储和读取char数组

我有三个char数组,我不希望Arduino将它存储在SRAM中,所以我想使用PROGMEM来存储和读取flash.

char *firstArr[]={"option 1","option 2","option 3","option 4"};
char *secondArr[]={"test 1","test 2"};
Run Code Online (Sandbox Code Playgroud)

c arduino

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

Android - 使用指纹扫描仪和密码来加密和解密多个字符串

在用户使用指纹扫描仪进行身份验证后,我需要结束对不同字符串和相关解密的加密。

遵循此项目(https://github.com/StylingAndroid/UserIdentity/tree/Part1)并更改“tryEncrypt”方法,如下所示:

  private boolean tryEncrypt(Cipher cipher) {
    try {
        cipher.doFinal(SECRET_BYTES);
        String one = "augusto";
        String two = "test@gmail.com";
        String three = "3333333331";
        byte[] oneEnc = cipher.doFinal(one.getBytes());
        byte[] twoEnc = cipher.doFinal(one.getBytes());
        byte[] threeEnc = cipher.doFinal(one.getBytes());
        Log.d("test", "oneEnc: " + Base64.encodeToString(oneEnc,0));
        Log.d("test", "twoEnc: " + Base64.encodeToString(twoEnc,0));
        Log.d("test", "threeEnc: " + Base64.encodeToString(threeEnc,0));

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

java.lang.IllegalStateException: IV has already been used. Reusing IV in encryption mode violates security best practices.
Run Code Online (Sandbox Code Playgroud)

正确的做法是什么? …

android

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

Android - 使用指纹认证加密和解密数据

我从 3 天开始就面临问题。我需要将 EditText 中的文本保存到 SharedPreferences 中。用户使用指纹扫描仪进行身份验证后,应将此文本加密保存在 SharedPreference 中。然后我需要解密这些数据,所以我需要一个永久存储机制来生成 SecretKey。

private SecretKey createKey(String keyName) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
    KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, ANDROID_KEY_STORE);
    keyGenerator.init(new KeyGenParameterSpec.Builder(keyName,
            KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
            .setKeySize(DEFAULT_KEY_SIZE)
            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
            .setUserAuthenticationRequired(true)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
            .build());
    return keyGenerator.generateKey();
}
Run Code Online (Sandbox Code Playgroud)

当我尝试KeyStore使用FileInputStream以下方法从文件加载时发生问题:

public static SecretKey getKeyFromKeystore(Context context) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {

    FileInputStream fis = null;
    try {
        fis = context.openFileInput(KEYSTORE_FILENAME);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
    // FileInputStream …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
2720
查看次数

如何在Android上实现OAuth2授权

我需要在我的应用中添加 OAuth2 授权。我只有客户端 ID、客户端机密和用户名(电子邮件)。我需要得到令牌。你能给我一些关于如何做到这一点的建议吗?库或示例代码?

android oauth-2.0

3
推荐指数
1
解决办法
6097
查看次数

如何将char*分配给char数组?

编译器告诉我"char*赋值给char [32]的不兼容类型"这是我的代码:

char* generalOperations[2]={"Off","On"};

 void test(){
   char value[32];
    switch(swapVariable){
     case 0:
      value=generalOperations[0]; //<==Error HERE!
     break;
    }

 }
Run Code Online (Sandbox Code Playgroud)

[解决了]:

  strcpy(value,generalOperations[0]);
Run Code Online (Sandbox Code Playgroud)

c++ char

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

标签 统计

android ×3

arduino ×1

c ×1

c++ ×1

char ×1

httpclient ×1

java ×1

login ×1

oauth-2.0 ×1

post ×1