//When Jesus had spoken these words, he went out with his disciples over the brook Kidron, where there was a garden, into which he and his disciples entered. (John 18:1) -----------------------------------------------AmigoOutputStream.java--------------------------------------------------------- package com.javarush.task.task18.task1812; import java.io.IOException; public interface AmigoOutputStream { void flush() throws IOException; void write(int b) throws IOException; void write(byte[] b) throws IOException; void write(byte[] b, int off, int len) throws IOException; void close() throws IOException; } ------------------------------------------------------------------------------------------------------------------------------ -----------------------------------------------QuestionFileOutputStream.java-------------------------------------------------- package com.javarush.task.task18.task1812; import java.io.*; /* РаÑÑиÑÑем AmigoOutputStream */ public class QuestionFileOutputStream implements AmigoOutputStream { AmigoOutputStream component; QuestionFileOutputStream(AmigoOutputStream component) { this.component = component; } public void flush() throws IOException { component.flush(); } public void write(int b) throws IOException { component.write(b); } public void write(byte[] b) throws IOException { component.write(b); } public void write(byte[] b, int off, int len) throws IOException { component.write(b, off, len); } public void close() throws IOException { System.out.println("ÐÑ Ð´ÐµÐ¹ÑÑвиÑелÑно Ñ Ð¾ÑиÑе закÑÑÑÑ Ð¿Ð¾Ñок? Ð/Ð"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String string = br.readLine(); if (string.equals("Ð")) { component.close(); } br.close(); } } ------------------------------------------------------------------------------------------------------------------------------ /* РаÑÑиÑÑем AmigoOutputStream ÐÑполÑзÑÑ Ñаблон пÑоекÑиÑÐ¾Ð²Ð°Ð½Ð¸Ñ Wrapper (Decorator) ÑаÑÑиÑÑ ÑÑнкÑионалÑноÑÑÑ AmigoOutputStream. РклаÑÑе QuestionFileOutputStream пÑи вÑзове меÑода close() должна бÑÑÑ Ñеализована ÑледÑÑÑÐ°Ñ ÑÑнкÑионалÑноÑÑÑ: 1. ÐÑвеÑÑи в конÑÐ¾Ð»Ñ ÑÑÐ°Ð·Ñ Â«ÐÑ Ð´ÐµÐ¹ÑÑвиÑелÑно Ñ Ð¾ÑиÑе закÑÑÑÑ Ð¿Ð¾Ñок? Ð/Ы. 2. СÑиÑайÑе ÑÑÑокÑ. 3. ÐÑли ÑÑиÑÐ°Ð½Ð½Ð°Ñ ÑÑÑока Ñавна «Ð«, Ñо закÑÑÑÑ Ð¿Ð¾Ñок. 4. ÐÑли ÑÑиÑÐ°Ð½Ð½Ð°Ñ ÑÑÑока не Ñавна «Ð«, Ñо не закÑÑваÑÑ Ð¿Ð¾Ñок. ТÑебованиÑ: 1.âÐнÑеÑÑÐµÐ¹Ñ AmigoOutputStream изменÑÑÑ Ð½ÐµÐ»ÑзÑ. 2.âÐлаÑÑ QuestionFileOutputStream должен ÑеализовÑваÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ AmigoOutputStream. 3.âÐлаÑÑ QuestionFileOutputStream должен иниÑиализиÑоваÑÑ Ð² конÑÑÑÑкÑоÑе поле Ñипа AmigoOutputStream. 4.âÐÑе меÑÐ¾Ð´Ñ QuestionFileOutputStream Ð´Ð¾Ð»Ð¶Ð½Ñ Ð´ÐµÐ»ÐµÐ³Ð¸ÑоваÑÑ Ñвое вÑполнение обÑекÑÑ AmigoOutputStream. 5.âÐеÑод close() должен ÑпÑаÑиваÑÑ Ñ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ "ÐÑ Ð´ÐµÐ¹ÑÑвиÑелÑно Ñ Ð¾ÑиÑе закÑÑÑÑ Ð¿Ð¾Ñок? Ð/Ð". 6.âÐеÑод close() должен закÑÑваÑÑ Ð¿Ð¾Ñок ÑолÑко в ÑлÑÑае, еÑли ÑÑиÑÐ°ÐµÑ Ñ ÐºÐ¾Ð½Ñоли оÑÐ²ÐµÑ "Ð". -----------------------------------------------AmigoOutputStream.java--------------------------------------------------------- package com.javarush.task.task18.task1812; import java.io.IOException; public interface AmigoOutputStream { void flush() throws IOException; void write(int b) throws IOException; void write(byte[] b) throws IOException; void write(byte[] b, int off, int len) throws IOException; void close() throws IOException; } ------------------------------------------------------------------------------------------------------------------------------ -----------------------------------------------QuestionFileOutputStream.java-------------------------------------------------- package com.javarush.task.task18.task1812; import java.io.*; * РаÑÑиÑÑем AmigoOutputStream * public class QuestionFileOutputStream implements AmigoOutputStream { } ------------------------------------------------------------------------------------------------------------------------------ */