Задача: "The Java Programming Language" Ken Arnold, James Gosling, David Holmes листинги, код, примеры из книги, исходники
Исходник: Глава 15, Ввод-Вывод (Chapter 15. Input-Output), Упражнение 15.3 (exercise) EncryptStreamTest class, язык: java [code #182, hits: 6462]
автор: - [добавлен: 15.09.2006]
  1. import java.io.*;
  2.  
  3. /**
  4. * Created by IntelliJ IDEA.
  5. * User: me
  6. * Date: 13.09.2006
  7. * Time: 17:16:39
  8. * To change this template use File | Settings | File Templates.
  9. */
  10. public class EncryptStreamTest {
  11. public static void main(String[] args) throws IOException {
  12. String fname = "encrypt.txt";
  13.  
  14. EncryptOutputStream enc = new EncryptOutputStream(fout);
  15.  
  16. byte[] data = new byte[] {1,2,3,4,5,6,7,8,9,10};
  17. enc.write(data);
  18. enc.close();
  19. fout.close();
  20.  
  21. FileInputStream fin = new FileInputStream(fname);
  22. DecryptInputStream decrypt = new DecryptInputStream(fin);
  23. int c;
  24. while ((c = decrypt.read()) != -1) {
  25. System.out.print((char)c);
  26. }
  27. System.out.println();
  28.  
  29. // // Attempt to read using alternative method
  30. // int num = decrypt.read(data);
  31. // System.out.println("num = " + num + ", result: " + (new String(data)));
  32. fin.close();
  33. decrypt.close();
  34. }
  35. }
  36.  
Тестировалось на: java 1.5.0_04

+добавить реализацию