-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
124 lines (82 loc) · 4.6 KB
/
Solution.java
File metadata and controls
124 lines (82 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//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 {
}
------------------------------------------------------------------------------------------------------------------------------
*/