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

replace ZipInputStream with ZipFile #10899

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -100,71 +100,48 @@ public IngestServiceShapefileHelper(File zippedShapefile, File rezipFolder){
//this.processFile(zippedShapefile, rezipFolder);

}
private FileInputStream getFileInputStream(File fileObject){
if (fileObject==null){
return null;
}
try {

private FileInputStream getFileInputStream(File fileObject){
if (fileObject==null){
return null;
}
try {
return new FileInputStream(fileObject);
} catch (FileNotFoundException ex) {
logger.severe("Failed to create FileInputStream from File: " + fileObject.getAbsolutePath());
return null;
}
}
private void closeFileInputStream(FileInputStream fis){
if (fis==null){
return;
}
}

private void closeFileInputStream(FileInputStream fis){
if (fis==null){
return;
}
try {
fis.close();
fis.close();
} catch (IOException ex) {
logger.info("Failed to close FileInputStream");
}
}
}

public boolean processFile() {

if ((!isValidFile(this.zippedShapefile))||(!isValidFolder(this.rezipFolder))){
return false;
}

// (1) Use the ShapefileHandler to the .zip for a shapefile
//
FileInputStream shpfileInputStream = this.getFileInputStream(zippedShapefile);
if (shpfileInputStream==null){
return false;
}

this.shpHandler = new ShapefileHandler(shpfileInputStream);
if (!shpHandler.containsShapefile()){
logger.severe("Shapefile was incorrectly detected upon Ingest (FileUtil) and passed here");
return false;
}

this.closeFileInputStream(shpfileInputStream);

// (2) Rezip the shapefile pieces
logger.info("rezipFolder: " + rezipFolder.getAbsolutePath());
shpfileInputStream = this.getFileInputStream(zippedShapefile);
if (shpfileInputStream==null){
return false;
}

boolean rezipSuccess;
try {
rezipSuccess = shpHandler.rezipShapefileSets(shpfileInputStream, rezipFolder);
this.shpHandler = new ShapefileHandler(zippedShapefile);
if (!shpHandler.containsShapefile()){
logger.severe("Shapefile was incorrectly detected upon Ingest (FileUtil) and passed here");
return false;
}
logger.info("rezipFolder: " + rezipFolder.getAbsolutePath());
return shpHandler.rezipShapefileSets(rezipFolder);
} catch (IOException ex) {
logger.severe("Shapefile was not correctly unpacked/repacked");
logger.severe("shpHandler message: " + shpHandler.errorMessage);
return false;
}

this.closeFileInputStream(shpfileInputStream);

return rezipSuccess;

// return createDataFiles(rezipFolder);

}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,18 @@ public static String determineFileType(File f, String fileName) throws IOExcepti
// Check for shapefile extensions as described here: http://en.wikipedia.org/wiki/Shapefile
//logger.info("Checking for shapefile");

ShapefileHandler shp_handler = new ShapefileHandler(new FileInputStream(f));
ShapefileHandler shp_handler = new ShapefileHandler(f);
if (shp_handler.containsShapefile()){
// logger.info("------- shapefile FOUND ----------");
fileType = ShapefileHandler.SHAPEFILE_FILE_TYPE; //"application/zipped-shapefile";
}

Optional<BagItFileHandler> bagItFileHandler = CDI.current().select(BagItFileHandlerFactory.class).get().getBagItFileHandler();
if(bagItFileHandler.isPresent() && bagItFileHandler.get().isBagItPackage(fileName, f)) {
fileType = BagItFileHandler.FILE_TYPE;
try {
Optional<BagItFileHandler> bagItFileHandler = CDI.current().select(BagItFileHandlerFactory.class).get().getBagItFileHandler();
if (bagItFileHandler.isPresent() && bagItFileHandler.get().isBagItPackage(fileName, f)) {
fileType = BagItFileHandler.FILE_TYPE;
}
} catch (Exception e) {
logger.warning("Error checking for BagIt package: " + e.getMessage());
}
}

Expand Down
Loading
Loading