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

use ZnapZipStore and construct zipFilePath correctly #500

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.bc.zarr.ZarrGroup;
import com.bc.zarr.storage.FileSystemStore;
import com.bc.zarr.storage.Store;
import com.bc.zarr.storage.ZipStore;
import org.esa.snap.core.dataio.AbstractProductReader;
import org.esa.snap.core.dataio.ProductIO;
import org.esa.snap.core.dataio.ProductReader;
Expand Down Expand Up @@ -204,7 +203,7 @@ protected Product readProductNodesImpl() throws IOException {
}
assert rootPath != null;
if (Files.isRegularFile(rootPath)) {
store = new ZipStore(rootPath);
store = new ZnapZipStore(rootPath);
} else {
store = new FileSystemStore(rootPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.esa.snap.dataio.znap.ZnapConstantsAndUtils.*;
import static com.bc.zarr.ZarrConstants.*;

import com.bc.zarr.storage.ZipStore;
import org.esa.snap.core.dataio.DecodeQualification;
import org.esa.snap.core.dataio.ProductReader;
import org.esa.snap.core.dataio.ProductReaderPlugIn;
Expand Down Expand Up @@ -77,7 +76,7 @@ public DecodeQualification getDecodeQualification(Object input) {
}
final boolean isValidZnapZipArchiveName = productRootName != null && productRootName.toString().toLowerCase().endsWith(ZNAP_ZIP_CONTAINER_EXTENSION);
if (isValidZnapZipArchiveName) {
try (ZipStore zipStore = new ZipStore(productRoot)) {
try (ZnapZipStore zipStore = new ZnapZipStore(productRoot)) {
final InputStream productHeaderStream = zipStore.getInputStream(FILENAME_DOT_ZGROUP);
final boolean productHeaderExist = productHeaderStream != null;
if (productHeaderExist) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ZnapZipStore(Path zipFilePath) throws IOException {
zipParams.put("create", "true");
zipParams.put("noCompression", "true");
}
final URI uri = URI.create("jar:file:" + zipFilePath.toUri().getPath());
final URI uri = URI.create("jar:" + zipFilePath.toUri());
zfs = getFileSystem(zipParams, uri);
internalRoot = zfs.getRootDirectories().iterator().next();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.esa.snap.dataio.znap;

import com.bc.ceres.annotation.STTM;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;

import static org.junit.Assert.*;

public class ZnapZipStoreTest {

@Test
@STTM("SNAP-3872")
public void testZnapZipStoreHandlesSpacesInPath() throws IOException {

Path tempDir = Files.createTempDirectory("znap_test");
Path zipFilePath = tempDir.resolve("test file with spaces.znap.zip");

HashMap<String, String> env = new HashMap<>();
env.put("create", "true");
try (FileSystem zipFs = FileSystems.newFileSystem(URI.create("jar:" + zipFilePath.toUri()), env)) {
Path dummyFile = zipFs.getPath("dummy.txt");
Files.write(dummyFile, "Dummy Text!".getBytes());
}

try {
new ZnapZipStore(zipFilePath);
} catch (IOException e) {
fail("ZnapZipStore constructor threw an exception for a path with spaces: " + e.getMessage());
} finally {
Files.deleteIfExists(zipFilePath);
Files.deleteIfExists(tempDir);
}

}
}