mpierse пре 7 година
родитељ
комит
f32f021958

+ 26
- 2
src/main/java/rocks/zipcode/AlphaCharDocument.java Прегледај датотеку

1
 package rocks.zipcode;
1
 package rocks.zipcode;
2
 
2
 
3
-import java.io.IOException;
3
+import java.io.*;
4
 
4
 
5
 /**
5
 /**
6
  * @author leon on 16/11/2018.
6
  * @author leon on 16/11/2018.
7
  */
7
  */
8
 public class AlphaCharDocument extends Document {
8
 public class AlphaCharDocument extends Document {
9
+
10
+private FileWriter fw;
11
+private String fileName;
12
+private File file = new File(fileName);
13
+
9
     public AlphaCharDocument(String fileName) throws IOException {
14
     public AlphaCharDocument(String fileName) throws IOException {
10
         super(fileName);
15
         super(fileName);
16
+        this.fileName = fileName;
17
+        fw = new FileWriter(fileName);
11
     }
18
     }
12
 
19
 
13
     @Override
20
     @Override
14
     public void write(String contentToBeWritten) {
21
     public void write(String contentToBeWritten) {
22
+        try {
23
+            isAlpha(contentToBeWritten);
24
+            fw.write(contentToBeWritten);
25
+        } catch (IOException ex) {
26
+            ex.printStackTrace();
27
+        }
15
     }
28
     }
16
 
29
 
17
-    private Boolean isAlpha(String s) {
30
+    public String read() throws FileNotFoundException {
31
+        BufferedReader br = new BufferedReader(new FileReader(file));
32
+        try {
33
+            return br.readLine();
34
+        } catch (IOException e) {
35
+            e.printStackTrace();
36
+        }
18
         return null;
37
         return null;
19
     }
38
     }
39
+
40
+    private void isAlpha(String s) throws IOException {
41
+        if(!s.matches("[a-zA-Z\\s]*"))
42
+            throw new IllegalArgumentException();
43
+    }
20
 }
44
 }

+ 1
- 1
src/main/java/rocks/zipcode/Document.java Прегледај датотеку

36
     }
36
     }
37
 
37
 
38
     @Override
38
     @Override
39
-    public String read() {
39
+    public String read() throws FileNotFoundException {
40
         return null;
40
         return null;
41
     }
41
     }
42
 
42
 

+ 2
- 1
src/main/java/rocks/zipcode/DocumentInterface.java Прегледај датотеку

1
 package rocks.zipcode;
1
 package rocks.zipcode;
2
 
2
 
3
 import java.io.File;
3
 import java.io.File;
4
+import java.io.FileNotFoundException;
4
 import java.util.List;
5
 import java.util.List;
5
 
6
 
6
 /**
7
 /**
13
 
14
 
14
     String read(Integer lineNumber);
15
     String read(Integer lineNumber);
15
 
16
 
16
-    String read();
17
+    String read() throws FileNotFoundException;
17
 
18
 
18
     void replaceAll(String stringToReplace, String replacementString);
19
     void replaceAll(String stringToReplace, String replacementString);
19
 
20
 

+ 1
- 1
src/test/java/rocks/zipcode/alphadocument/AlphaDocumentWriteTest.java Прегледај датотеку

45
         // when
45
         // when
46
         documentWriter.write(expected);
46
         documentWriter.write(expected);
47
         String actual = documentWriter.read();
47
         String actual = documentWriter.read();
48
-
48
+        System.out.println(actual);
49
         // then
49
         // then
50
         Assert.assertEquals(expected, actual);
50
         Assert.assertEquals(expected, actual);
51
     }
51
     }