diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..5c98b42
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml
\ No newline at end of file
diff --git a/.idea/Teaching-HEIGVD-RES-2020-Labo-Java-IO.iml b/.idea/Teaching-HEIGVD-RES-2020-Labo-Java-IO.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/Teaching-HEIGVD-RES-2020-Labo-Java-IO.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..a675ee7
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e611cf4
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LabJavaIO/pom.xml b/LabJavaIO/pom.xml
index 6224422..a34d7d5 100644
--- a/LabJavaIO/pom.xml
+++ b/LabJavaIO/pom.xml
@@ -39,6 +39,14 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 11
+
+
diff --git a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Application.java b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Application.java
index ad87a7d..07fd8dc 100644
--- a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Application.java
+++ b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Application.java
@@ -7,10 +7,11 @@
import ch.heigvd.res.labio.interfaces.IFileVisitor;
import ch.heigvd.res.labio.quotes.QuoteClient;
import ch.heigvd.res.labio.quotes.Quote;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
+
+import java.io.*;
+import java.nio.file.*;
+import java.util.List;
+import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
@@ -90,6 +91,7 @@ public void fetchAndStoreQuotes(int numberOfQuotes) throws IOException {
* one method provided by this class, which is responsible for storing the content of the
* quote in a text file (and for generating the directories based on the tags).
*/
+ this.storeQuote(quote,("quote-"+Integer.toString(i+1)));
LOG.info("Received a new joke with " + quote.getTags().size() + " tags.");
for (String tag : quote.getTags()) {
LOG.info("> " + tag);
@@ -104,7 +106,7 @@ public void fetchAndStoreQuotes(int numberOfQuotes) throws IOException {
* @throws IOException
*/
void clearOutputDirectory() throws IOException {
- FileUtils.deleteDirectory(new File(WORKSPACE_DIRECTORY));
+ FileUtils.deleteDirectory(new File(WORKSPACE_DIRECTORY));
}
/**
@@ -122,8 +124,26 @@ void clearOutputDirectory() throws IOException {
* @param filename the name of the file to create and where to store the quote text
* @throws IOException
*/
- void storeQuote(Quote quote, String filename) throws IOException {
- throw new UnsupportedOperationException("The student has not implemented this method yet.");
+ void storeQuote(Quote quote, String filename) throws IOException
+ {
+ List tags=quote.getTags();
+ String path=(WORKSPACE_DIRECTORY+"/");
+ for(String tag:tags)
+ {
+ path+=(tag+"/");
+ }
+ File file=new File(path);
+ if ((!file.exists()) && !file.mkdirs())
+ {
+ throw new UnsupportedOperationException("Directories not created");
+ }
+
+ file=new File(path+filename+".utf8");
+ file.createNewFile();
+ FileWriter writer=new FileWriter(file);
+ writer.write(quote.getQuote());
+ writer.flush();
+ writer.close();
}
/**
@@ -135,11 +155,15 @@ void printFileNames(final Writer writer) {
explorer.explore(new File(WORKSPACE_DIRECTORY), new IFileVisitor() {
@Override
public void visit(File file) {
- /*
- * There is a missing piece here. Notice how we use an anonymous class here. We provide the implementation
- * of the the IFileVisitor interface inline. You just have to add the body of the visit method, which should
- * be pretty easy (we want to write the filename, including the path, to the writer passed in argument).
- */
+ try
+ {
+ writer.write(file.getPath());
+ writer.write("\n");
+ }
+ catch (IOException except)
+ {
+ //make Java happy
+ }
}
});
}
diff --git a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Utils.java b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Utils.java
index c8a3a5a..8f82d5a 100644
--- a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Utils.java
+++ b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Utils.java
@@ -9,7 +9,7 @@
public class Utils {
private static final Logger LOG = Logger.getLogger(Utils.class.getName());
-
+ private static final int NB_STRINGS_RESULT=2;
/**
* This method looks for the next new line separators (\r, \n, \r\n) to extract
* the next line in the string passed in arguments.
@@ -19,8 +19,39 @@ public class Utils {
* the line separator, the second element is the remaining text. If the argument does not
* contain any line separator, then the first element is an empty string.
*/
- public static String[] getNextLine(String lines) {
- throw new UnsupportedOperationException("The student has not implemented this method yet.");
+ public static String[] getNextLine(String lines)
+ {
+ String[] result=new String[NB_STRINGS_RESULT];
+
+ for(int x=0;x=LOWER_MIN && c<=LOWER_MAX)
+ {
+ return ((char)(c-=LOW_UP_GAP));
+ }
+ else
+ {
+ return c;
+ }
+ }
}
diff --git a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformer.java b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformer.java
index 4beca48..319f0ac 100644
--- a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformer.java
+++ b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformer.java
@@ -1,5 +1,8 @@
package ch.heigvd.res.labio.impl.transformers;
+import ch.heigvd.res.labio.impl.filters.FileNumberingFilterWriter;
+import ch.heigvd.res.labio.impl.filters.UpperCaseFilterWriter;
+
import java.io.Writer;
/**
@@ -15,16 +18,13 @@ public class CompleteFileTransformer extends FileTransformer {
@Override
public Writer decorateWithFilters(Writer writer) {
- if (true) {
- throw new UnsupportedOperationException("The student has not implemented this method yet.");
- }
/*
* If you uncomment the following line (and get rid of th 3 previous lines...), you will restore the decoration
* of the writer (connected to the file. You can see that you first decorate the writer with an UpperCaseFilterWriter, which you then
* decorate with a FileNumberingFilterWriter. The resulting writer is used by the abstract class to write the characters read from the
* input files. So, the input is first prefixed with line numbers, then transformed to uppercase, then sent to the output file.f
*/
- //writer = new FileNumberingFilterWriter(new UpperCaseFilterWriter(writer));
+ writer = new FileNumberingFilterWriter(new UpperCaseFilterWriter(writer));
return writer;
}
diff --git a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/FileTransformer.java b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/FileTransformer.java
index 18e3f14..866561d 100644
--- a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/FileTransformer.java
+++ b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/FileTransformer.java
@@ -53,11 +53,18 @@ public void visit(File file) {
Writer writer = new OutputStreamWriter(new FileOutputStream(file.getPath()+ ".out"), "UTF-8"); // the bug fix by teacher
writer = decorateWithFilters(writer);
- /*
- * There is a missing piece here: you have an input reader and an ouput writer (notice how the
- * writer has been decorated by the concrete subclass!). You need to write a loop to read the
- * characters and write them to the writer.
- */
+ while(true)
+ {
+ int c=reader.read();
+ if(c>(-1))
+ {
+ writer.write(c);
+ }
+ else
+ {
+ break;
+ }
+ }
reader.close();
writer.flush();
diff --git a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/NoOpFileTransformer.java b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/NoOpFileTransformer.java
index 5971a30..83670d4 100644
--- a/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/NoOpFileTransformer.java
+++ b/LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/transformers/NoOpFileTransformer.java
@@ -13,14 +13,8 @@ public class NoOpFileTransformer extends FileTransformer {
@Override
public Writer decorateWithFilters(Writer writer) {
- throw new UnsupportedOperationException("The student has not implemented this method yet.");
- /*
- * The NoOpFileTransformer does not apply any transformation of the character stream
- * (no uppercase, no line number, etc.). So, we don't need to decorate the writer connected to
- * the output file at all. Just uncomment the following line and get rid of the UnsupportedOperationException and
- * you will be all set.
- */
- //return writer;
+
+ return writer;
}
}
diff --git a/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/ApplicationTest.java b/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/ApplicationTest.java
index 354a666..3423f3e 100644
--- a/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/ApplicationTest.java
+++ b/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/ApplicationTest.java
@@ -146,5 +146,4 @@ public void theApplicationShouldBeAbleToGenerateTheListOfFileNames() throws IOEx
assertTrue(applicationReturnsValidFilePaths);
}
-
-}
+}
\ No newline at end of file
diff --git a/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformerTest.java b/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformerTest.java
index 84d7198..2aa6d86 100644
--- a/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformerTest.java
+++ b/LabJavaIO/src/test/java/ch/heigvd/res/labio/impl/transformers/CompleteFileTransformerTest.java
@@ -38,5 +38,4 @@ public void itShouldApplyTwoTransformationsOnAFile() throws IOException {
assertTrue( FileUtils.contentEquals(expectedFile, outputFile) );
FileUtils.deleteDirectory(new File("./tmp"));
}
-
}