Skip to content

Commit

Permalink
Fixed another bug with rpt integrate related to auto content type/enc…
Browse files Browse the repository at this point in the history
…oding detection
  • Loading branch information
Aklakan committed Feb 27, 2024
1 parent 0dd361e commit ad5fa14
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,17 @@ public static int sparqlIntegrate(CmdSparqlIntegrateMain cmd) throws Exception {
x -> ContentTypeUtils.getCtExtensions().getAlternatives().containsKey(x.toLowerCase()),
x -> ContentTypeUtils.getCodingExtensions().getAlternatives().containsKey(x.toLowerCase()));

// If a format is given it takes precedence - otherwise try to use the filename
String outFormat = cmd.outFormat;
if (outFormat == null) {
String formatSource = outFormat == null
? outFilename
: outFormat;

if (formatSource != null) {
// Try to derive the outFormat from the filename - if given.
if (outFilename != null) {
FileName fn = fileNameParser.parse(outFilename);
outFormat = fn.getContentPart();
rawOutEncodings.addAll(fn.getEncodingParts());
}
FileName fn = fileNameParser.parse(formatSource);
outFormat = fn.getContentPart();
rawOutEncodings.addAll(fn.getEncodingParts());
}

CompressorStreamFactory csf = CompressorStreamFactory.getSingleton();
Expand All @@ -267,24 +270,24 @@ public static int sparqlIntegrate(CmdSparqlIntegrateMain cmd) throws Exception {
throw new RuntimeException("Cannot write to specified output file: " + outFile.toAbsolutePath());
}

if (outFormat == null) {
FileName fileName = fileNameParser.parse(outFilename);
String contentPart = fileName.getContentPart();

Lang lang = RDFLanguagesEx.findLang(contentPart);
rawOutEncodings.addAll(fileName.getEncodingParts());

// fileName = FileNameUtils.deconstruct(outFilename);

// Lang lang = RDFDataMgr.determineLang(outFilename, null, null);
if (lang != null) {
RDFFormat fmt = RDFWriterRegistry.defaultSerialization(lang);
outFormat = fmt == null ? null : fmt.toString();
logger.info("Inferred output format from " + outFilename + ": " + outFormat);
} else {
throw new RuntimeException("Failed to determine output format");
}
}
// if (outFormat == null) {
// FileName fileName = fileNameParser.parse(outFilename);
// String contentPart = fileName.getContentPart();
//
// Lang lang = RDFLanguagesEx.findLang(contentPart);
// rawOutEncodings.addAll(fileName.getEncodingParts());
//
// // fileName = FileNameUtils.deconstruct(outFilename);
//
// // Lang lang = RDFDataMgr.determineLang(outFilename, null, null);
// if (lang != null) {
// RDFFormat fmt = RDFWriterRegistry.defaultSerialization(lang);
// outFormat = fmt == null ? null : fmt.toString();
// logger.info("Inferred output format from " + outFilename + ": " + outFormat);
// } else {
// throw new RuntimeException("Failed to determine output format");
// }
// }

Path parent = outFile.getParent();
String tmpName = "." + outFile.getFileName().toString() + ".tmp";
Expand Down

0 comments on commit ad5fa14

Please sign in to comment.