Skip to content

getFile function #2

Description

@Stormuzi

Hi,I feel that there may be a problem with this code.
If the line is short, for example ,"a", when the file is exhausted, starting recursion, "" will be passed in.
There will be a stringIndexOutOfBoundsException

protected File getFile(String prefix, String line) {
    char start = line.charAt(0);
    String filename = (prefix + start).toLowerCase();

    File file = fileSplitter.getTempFiles().get(filename);
    if (file == null) {
        file = Paths.get(tempFilesDir, filename + ".txt").toFile();
        file.deleteOnExit();
        fileSplitter.addTempFile(filename, file);
    } else {
        Long maxTempFileSize = Long.valueOf(ExternalSortingProperties.MAX_TEMP_FILE_SIZE.value());
        if (fileSplitter.isFileExhausted(filename) || file.length() >= maxTempFileSize) {
            fileSplitter.addExhaustedFile(filename);
            file = getFile(filename, line.substring(1));
        }
    }
    fileSplitter.checkSameFirstCharFilename(file);
    return file;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions