Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhance] Handle filePath in one go instead of repeating process and … #824

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

public final class Document {
private final File file;
private final String filePath;
private final HeaderDefinition headerDefinition;
private final Charset encoding;
private final String[] keywords;
Expand All @@ -42,6 +43,7 @@ public final class Document {
public Document(File file, HeaderDefinition headerDefinition, Charset encoding, String[] keywords, DocumentPropertiesLoader documentPropertiesLoader) {
this.keywords = keywords.clone();
this.file = file;
this.filePath = file.getPath().replace('\\', '/');
this.headerDefinition = headerDefinition;
this.encoding = encoding;
this.documentPropertiesLoader = documentPropertiesLoader;
Expand All @@ -56,7 +58,7 @@ public File getFile() {
}

public String getFilePath() {
return getFile().getPath().replace('\\', '/');
return filePath;
}

public Charset getEncoding() {
Expand All @@ -75,13 +77,13 @@ public boolean hasHeader(Header header, boolean strictCheck) {
String headerOnOnelIne = mergeProperties(header.asOneLineString());
return fileHeaderOneLine.contains(remove(headerOnOnelIne, headerDefinition.getFirstLine().trim(), headerDefinition.getEndLine().trim(), headerDefinition.getBeforeEachLine().trim()));
} catch (IOException e) {
throw new IllegalStateException("Cannot read file " + getFilePath() + ". Cause: " + e.getMessage(), e);
throw new IllegalStateException("Cannot read file " + filePath + ". Cause: " + e.getMessage(), e);
}
}
try {
return header.isMatchForText(this, headerDefinition, true, encoding);
} catch (IOException e) {
throw new IllegalStateException("Cannot read file " + getFilePath() + ". Cause: " + e.getMessage(), e);
throw new IllegalStateException("Cannot read file " + filePath + ". Cause: " + e.getMessage(), e);
}
}

Expand All @@ -103,7 +105,7 @@ public void saveTo(File dest) {
try {
FileUtils.write(dest, parser.getFileContent().getContent(), encoding);
} catch (IOException e) {
throw new IllegalStateException("Cannot write new header in file " + getFilePath() + ". Cause: " + e.getMessage(), e);
throw new IllegalStateException("Cannot write new header in file " + filePath + ". Cause: " + e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -138,6 +140,6 @@ public boolean headerDetected() {

@Override
public String toString() {
return "Document " + getFilePath();
return "Document " + filePath;
}
}