Skip to content

Commit

Permalink
Merge pull request usdot-jpo-ode#278 from usdot-jpo-ode/node-xy-docke…
Browse files Browse the repository at this point in the history
…rBuildsImage_filepath-fix

Add .toString() to fix filepath issues
  • Loading branch information
mvs5465 committed Nov 29, 2018
2 parents be69071 + 71cf3f6 commit af141ab
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
public class ImporterProcessor {

private static final Logger logger = LoggerFactory.getLogger(ImporterProcessor.class);
// Removed for ODE-559
// private FileDecoderPublisher decoderPublisherManager;
// Removed for ODE-559
// private FileDecoderPublisher decoderPublisherManager;
private FileAsn1CodecPublisher codecPublisher;
private OdeProperties odeProperties;
private ImporterFileType fileType;
private Pattern gZipPattern = Pattern.compile("application/.*gzip");
private Pattern zipPattern = Pattern.compile("application/.*zip.*");

public ImporterProcessor(OdeProperties odeProperties, ImporterFileType fileType) {
// Removed for ODE-559
// this.decoderPublisherManager = new FileDecoderPublisher(odeProperties);
// Removed for ODE-559
// this.decoderPublisherManager = new FileDecoderPublisher(odeProperties);
this.codecPublisher = new FileAsn1CodecPublisher(odeProperties);
this.odeProperties = odeProperties;
this.fileType = fileType;
Expand Down Expand Up @@ -70,33 +70,36 @@ public void processAndBackupFile(Path filePath, Path backupDir, Path failureDir)
* ODE-559 vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
* removed lines below when asn1_codec was integrated
*/
// try (InputStream inputStream = new FileInputStream(filePath.toFile())) {
// BufferedInputStream bis = new BufferedInputStream(inputStream, odeProperties.getImportProcessorBufferSize());
// decoderPublisherManager.decodeAndPublishFile(filePath, bis, fileType);
// bis = new BufferedInputStream(inputStream, odeProperties.getImportProcessorBufferSize());
// } catch (Exception e) {
// logger.error("Unable to open or process file: " + filePath, e);
// }
// try (InputStream inputStream = new FileInputStream(filePath.toFile())) {
// BufferedInputStream bis = new BufferedInputStream(inputStream, odeProperties.getImportProcessorBufferSize());
// decoderPublisherManager.decodeAndPublishFile(filePath, bis, fileType);
// bis = new BufferedInputStream(inputStream, odeProperties.getImportProcessorBufferSize());
// } catch (Exception e) {
// logger.error("Unable to open or process file: " + filePath, e);
// }
// ODE-559 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

// ODE-559
boolean success = true;
InputStream inputStream = null;
BufferedInputStream bis = null;

try {
inputStream = new FileInputStream(filePath.toFile());
String probeContentType = Files.probeContentType(filePath);
if (probeContentType != null && gZipPattern.matcher(probeContentType).matches() || filePath.endsWith("gz")) {
inputStream = new GZIPInputStream(inputStream);
bis = publishFile(filePath, inputStream);
} else if (probeContentType != null && zipPattern.matcher(probeContentType).matches() || filePath.endsWith("zip")) {
if ((probeContentType != null && gZipPattern.matcher(probeContentType).matches()) || filePath.toString().toLowerCase().endsWith("gz")) {
logger.info("Treating as gzip file");
inputStream = new GZIPInputStream(inputStream);
bis = publishFile(filePath, inputStream);
} else if ((probeContentType != null && zipPattern.matcher(probeContentType).matches()) || filePath.toString().endsWith("zip")) {
logger.info("Treating as zip file");
inputStream = new ZipInputStream(inputStream);
ZipInputStream zis = (ZipInputStream)inputStream;
while (zis.getNextEntry() != null) {
bis = publishFile(filePath, inputStream);
}
} else {
logger.info("Treating as unknown file");
bis = publishFile(filePath, inputStream);
}
} catch (Exception e) {
Expand All @@ -115,7 +118,7 @@ public void processAndBackupFile(Path filePath, Path backupDir, Path failureDir)
logger.error("Failed to close file stream: {}", e);
}
}

try {
if (success) {
OdeFileUtils.backupFile(filePath, backupDir);
Expand Down

0 comments on commit af141ab

Please sign in to comment.