Как использовать PipedInputStream и PipedOutputStream - PullRequest
0 голосов
/ 11 сентября 2018

Есть много примеров использования при преобразовании OutputStream в InputStream.

Как мне заполнить недостающие части ниже?

Я имею в виду putDataOnOutputStream(out) метод.

Если все еще необходимо использовать ByteArrays, в этом случае не имеет смысла, каково преимущество памяти при использовании PipeLines

Мне нужно завершить convertToInputStream;

 public static InputStream decrypt(String keyCode, String file) throws IOException, InterruptedException {

        OutputStream out;

        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/Pkcs5Padding");
          /****** decyption code 
         **/
            out = new BufferedOutputStream(new FileOutputStream("C:decyrptedText.txt"));

            for(int readBytes = in.read(buffer); readBytes>-1; readBytes = in.read(buffer)) {
                byte[] decrypted = cipher.update(buffer, 0, readBytes);
                out.write(decrypted);
            }
            byte[] decrypted = cipher.doFinal();
            out.write(decrypted);
            out.flush();
            out.close();
            in.close();

        } catch (Exception e) {
            throw new IllegalStateException(e);
        }

        return convertToInputStream(out); //  
    }


   public static InputStream convertToInputStream(OutputStream outputStream) throws IOException, InterruptedException {

    PipedInputStream in = new PipedInputStream();
        PipedOutputStream out = new PipedOutputStream(in);
        new Thread(
                new Runnable(){
                    public void run(){
                        //put your code that writes data to the outputstream here.
                        putDataOnOutputStream(outputStream);
                    }
                }
        ).start();
        //data can be read from the pipedInputStream here.
        processDataFromInputStream(in);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...