import java.io.File;
import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
public final class BugtraqConfig {
// Constants ==============================================================
FileMode entmode = tw.getFileMode(0);
if (FileMode.REGULAR_FILE == entmode) {
ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB);
- content = new String(ldr.getCachedBytes(), commit.getEncoding());
+ content = new String(ldr.getCachedBytes(), guessEncoding(commit));
break;
}
}
return baseConfig;
}
+ @NotNull
+ private static Charset guessEncoding(RevCommit commit) {
+ try {
+ return commit.getEncoding();
+ } catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
+ return UTF_8;
+ }
+ }
+
@Nullable
private static String getString(@Nullable String subsection, @NotNull String key, @NotNull Config config, @Nullable Config baseConfig) {
final String value = config.getString(BUGTRAQ, subsection, key);