Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
eb6248a
Branch created just to pull request to master
bruno-darochac Mar 12, 2021
5251552
Merge pull request #1 from Otabiel/fb-upperCase
bruno-darochac Mar 12, 2021
8afef28
Class Utils terminée. Elle passe tout les tests
bruno-darochac Mar 12, 2021
acb6e8a
Merge pull request #2 from Otabiel/fb-Utils
bruno-darochac Mar 12, 2021
221cf82
DFS terminé et passe les tests
nilsbasset Mar 12, 2021
16d1354
Merge pull request #3 from Otabiel/fb-DFSFileExplorer
nilsbasset Mar 12, 2021
13fe62c
Mise en place de la numérotation des lignes pour Mac, Windows et Linux
bruno-darochac Mar 19, 2021
df544b7
Merge pull request #4 from Otabiel/fb-FileNumberingFilterWriter
bruno-darochac Mar 19, 2021
adfdb87
UpperCaseFilterWriter fini et passe les tests
nilsbasset Mar 19, 2021
7d92f80
Rajouter les inculdes nécessaires
bruno-darochac Mar 19, 2021
f1ca61a
Compléter le fichier à l'aveugle en espérant que cela passes quand on…
bruno-darochac Mar 19, 2021
3315d5b
Merge pull request #5 from Otabiel/fb-CompleteFileTranformer
bruno-darochac Mar 19, 2021
d2af847
Merge pull request #6 from Otabiel/fb-Application
bruno-darochac Mar 19, 2021
c8f0210
FileTransformer fait mais a tester avec le tout
nilsbasset Mar 19, 2021
9097523
Merge pull request #7 from Otabiel/fb-FileTransformer
nilsbasset Mar 19, 2021
991cb53
décommenter le return
bruno-darochac Mar 19, 2021
cca8ac3
Merge pull request #8 from Otabiel/fb-noopfile
bruno-darochac Mar 19, 2021
0a64307
Supprimé throw
bruno-darochac Mar 23, 2021
0adde5b
Voilà
bruno-darochac Mar 23, 2021
57eb469
Merge pull request #9 from Otabiel/fb-CompleteFileTranformer
bruno-darochac Mar 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
import ch.heigvd.res.labio.quotes.QuoteClient;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.io.*;
import java.net.URISyntaxException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -98,6 +96,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).
*/
storeQuote(quote, "quote-" + i + ".utf8");
LOG.info("Received a new joke with " + quote.getTags().size() + " tags.");
for (String tag : quote.getTags()) {
LOG.info("> " + tag);
Expand Down Expand Up @@ -133,7 +132,19 @@ void clearOutputDirectory() throws IOException {
* @throws IOException
*/
void storeQuote(Quote quote, String filename) throws IOException {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
List<String> quotes = quote.getTags();

String path = WORKSPACE_DIRECTORY + "/";
for(String t : quotes)
path += (t + "/");

File file = new File(path);
file.mkdirs();

path += filename;
FileWriter fileWriter = new FileWriter(path);
fileWriter.write(quote.getQuote());
fileWriter.close();
}

/**
Expand All @@ -150,6 +161,11 @@ public void visit(File file) {
* 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() + "\n");
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
Expand Down
43 changes: 42 additions & 1 deletion LabJavaIO/src/main/java/ch/heigvd/res/labio/impl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,48 @@ public class Utils {
* 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.");
String[] retour = new String[2];

int idx = lines.indexOf("\r") + 1;
int idx1 = lines.indexOf("\n") + 1;

if(idx == 0 && idx1 == 0){
retour[1] = lines;
retour[0] = "";
return retour;
}

if(idx == idx1 - 1){
if(idx1 == lines.length()){
retour[0] = lines;
retour[1] = "";
} else {
retour[0] = lines.substring(0, idx1);
retour[1] = lines.substring(idx1);
}
} else if (idx < idx1) {
if(idx == 0){ //idx1 est plus petit
retour[0] = lines.substring(0, idx1);
retour[1] = lines.substring(idx1);
} else { //idx est vraiment plus petit
retour[0] = lines.substring(0, idx);
retour[1] = lines.substring(idx);
}
} else {
if(idx1 == 0){ //idx est plus petit
retour[0] = lines.substring(0, idx);
retour[1] = lines.substring(idx);
} else { //idx1 est vraiment plus petit
retour[0] = lines.substring(0, idx1);
retour[1] = lines.substring(idx1);
}
}


//retour[0] = part1;
//retour[1] = part2;

return retour;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@
import ch.heigvd.res.labio.interfaces.IFileVisitor;

import java.io.File;
import java.util.Arrays;

/**
* This implementation of the IFileExplorer interface performs a depth-first
* exploration of the file system and invokes the visitor for every encountered
* node (file and directory). When the explorer reaches a directory, it visits all
* files in the directory and then moves into the subdirectories.
*
*
* Site : https://www.techiedelight.com/traverse-given-directory-bfs-dfs-java/
*
* @author Olivier Liechti
*/
public class DFSFileExplorer implements IFileExplorer {

@Override
public void explore(File rootDirectory, IFileVisitor vistor) {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
vistor.visit(rootDirectory);
File[] listOfFilesAndDirectory = rootDirectory.listFiles();
if (listOfFilesAndDirectory != null){
Arrays.sort(listOfFilesAndDirectory);
for (File file : listOfFilesAndDirectory){
explore(file, vistor);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,47 @@
public class FileNumberingFilterWriter extends FilterWriter {

private static final Logger LOG = Logger.getLogger(FileNumberingFilterWriter.class.getName());
private int nbLine = 0;
private int lastcharChecked;

public FileNumberingFilterWriter(Writer out) {
super(out);
}

@Override
public void write(String str, int off, int len) throws IOException {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
for(int i = off; i < off + len; ++i){
this.write(str.charAt(i));
}
}

@Override
public void write(char[] cbuf, int off, int len) throws IOException {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
for(int i = off; i < off + len; ++i){
this.write(cbuf[i]);
}
}

@Override
public void write(int c) throws IOException {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
if(nbLine == 0){
out.write(++nbLine + "\t");
}

//Pour MacOS
if(lastcharChecked == '\r' && c != '\n'){
out.write(++nbLine + "\t");
out.write(c); //Si je ne rajoute pas ça on affiche pas le caractère courrant
} else if(c == '\n'){
out.write("\n" + ++nbLine + "\t");
} else {
out.write(c);
}




lastcharChecked = c;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.io.FilterWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Locale;
import java.lang.String;

//https://docs.oracle.com/javase/7/docs/api/java/io/Writer.html

/**
*
Expand All @@ -16,17 +20,21 @@ public UpperCaseFilterWriter(Writer wrappedWriter) {

@Override
public void write(String str, int off, int len) throws IOException {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
super.write(str.toUpperCase(), off, len);
}

@Override
public void write(char[] cbuf, int off, int len) throws IOException {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
String str = new String(cbuf);
super.write(str.toUpperCase(), off, len);
}

@Override
public void write(int c) throws IOException {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
if(c >= 97 && c <= 122){
super.write(c-32);
}else{
super.write(c);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@
*
* @author Olivier Liechti
*/

import ch.heigvd.res.labio.impl.filters.FileNumberingFilterWriter;
import ch.heigvd.res.labio.impl.filters.UpperCaseFilterWriter;

import java.io.Writer;

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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public void visit(File file) {
* writer has been decorated by the concrete subclass!). You need to write a loop to read the
* characters and write them to the writer.
*/
int i;
while((i = reader.read()) != -1) {
writer.write(i);
}

reader.close();
writer.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public class NoOpFileTransformer extends FileTransformer {

@Override
public Writer decorateWithFilters(Writer writer) {
throw new UnsupportedOperationException("The student has not implemented this method yet.");
//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;
}

}