Advertisement
jaVer404

level18.lesson08.task03

Nov 4th, 2015
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. package com.javarush.test.level18.lesson08.task03;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6.  
  7. /* AmigoOutputStream
  8. 1 Измените класс AmigoOutputStream так, чтобы он стал Wrapper-ом для класса FileOutputStream. Используйте наследование.
  9. 2 При вызове метода close() должны выполняться следующая последовательность действий:
  10. 2.1 вызвать метод flush()
  11. 2.2 дописать следующий текст [JavaRush © 2012-2013 All rights reserved.], используйте метод getBytes()
  12. 2.3 закрыть поток методом close()
  13. */
  14.  
  15. public class AmigoOutputStream extends FileOutputStream {
  16.     public static String fileName = "C:/tmp/result.txt";
  17.     private FileOutputStream fileOutputStream;
  18.  
  19.     public AmigoOutputStream(FileOutputStream fOS) throws FileNotFoundException
  20.     {
  21.         super(fileName);
  22.         this.fileOutputStream = fOS;
  23.     }
  24.  
  25.     @Override
  26.     public void close() throws IOException
  27.     {
  28.         fileOutputStream.flush();
  29.         fileOutputStream.write(new String("JavaRush © 2012-2013 All rights reserved.").getBytes());
  30.         fileOutputStream.close();
  31.     }
  32.     public void flush() throws IOException {
  33.         fileOutputStream.flush();
  34.     }
  35.  
  36.     public void write(int b) throws IOException{
  37.         fileOutputStream.write(b);
  38.     }
  39.  
  40.  
  41.     public void write(byte[] b) throws IOException{
  42.         fileOutputStream.write(b);
  43.     }
  44.  
  45.     public void write(byte[] b, int off, int len) throws IOException{
  46.         fileOutputStream.write(b,off,len);
  47.     }
  48.  
  49.     public static void main(String[] args) throws FileNotFoundException {
  50.         new AmigoOutputStream(new FileOutputStream(fileName));
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement