bmwinstead / enigma-project

Other
1 stars 1 forks source link

GUI: File Upload When Text Files Have Spaces #26

Closed ikleyjl closed 10 years ago

ikleyjl commented 10 years ago

When the file upload function is used in the GUI, if the file contains spaces, only the final word is encrypted.

EOhlmacher commented 10 years ago

I believe I have fixed this. can someone else verify & close so it isn't just my word for it? :)

wadolph commented 10 years ago

I tried to load a text file and use a text entry, but it doesn't seem to work. What's the delimiter on line 450 (scanner = new Scanner(file).useDelimiter("\Z");) supposed to match? If it is supposed to be whitespace, it should be \s. If non-word, \W. I think the delimiter is the issue. http://docs.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html

EOhlmacher commented 10 years ago

According to http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html it should just be the end of input. The issue causing the original problem was that it was defaulting to white space, and therefore was not converting the entire doc to a string. I will investigate this new issue. I have a suspicion it has to do with special characters, which we plan to get rid of anyway.

bmwinstead commented 10 years ago

I think the easiest thing to do to resolve this is probably use the new file io package. Also, if you're using "The end of the input but for the final terminator, if any" as a delimiter, when you call "scanner.next();" it's going to return all input up to the next delimiter. The first time you call it, it'll give you everything up to the "the end of the input but for the final terminator, if any". The second time, it'll return the last of the input, and since you're using "fileString = scanner.next();" it'll just count the last word.

bmwinstead commented 10 years ago

This is what the code would look like using the nio package:

    String fileString = "";
    try {
        List<String> allFileLines = Files.readAllLines(Paths.get(s), Charset.defaultCharset());
        for(String a : allFileLines){
            fileString += a;
        }
    } catch (IOException ex) {
        Logger.getLogger(EnigmaGUI.class.getName()).log
        (Level.SEVERE, null, ex);
    }
bmwinstead commented 10 years ago

The initial issue was the line "fileString = scan.next()" overwriting the previous input, leaving only the last entered thing. I fixed and pushed.

It should be noted that now spaces aren't preserved at all, even if I manually insert a space in the line "fileString += scanner.next() + " "; " A new thing to investigate.

bmwinstead commented 10 years ago

Whoops. only changed one of the action listeners at first. It's good now.