Skip to content

Commit

Permalink
Merge branch 'maint-5.x' into scale-offset
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyajohnson committed May 9, 2023
2 parents 4f033f0 + 413a6f0 commit c4c7ea1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private static ucar.unidata.io.RandomAccessFile downloadAndDecompress(ucar.unida
* @return RandomAccessFile for the object at location
*/
public static ucar.unidata.io.RandomAccessFile getRaf(String location, int buffer_size) throws IOException {
String uriString = location.trim();
String uriString = removeFragment(location.trim());
if (buffer_size <= 0)
buffer_size = default_buffersize;

Expand Down Expand Up @@ -473,6 +473,10 @@ public static ucar.unidata.io.RandomAccessFile getRaf(String location, int buffe
return raf;
}

private static String removeFragment(String uriString) {
return uriString.split("#")[0];
}

private static boolean looksCompressed(String filename) {
// return true if filename ends with a compressed suffix or contains a compressed suffix followed by a delimiter
// (i.e. path to a compressed entry)
Expand Down
7 changes: 5 additions & 2 deletions cdm/s3/src/main/java/thredds/filesystem/s3/ControllerS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,27 @@ private static class FilteredIterator implements Iterator<MFile> {
this.mc = mc;
this.wantDirs = wantDirs;
this.fullInventory = false;
this.next = nextFilteredFile();
}

FilteredIterator(CollectionConfig mc, Iterator<MFile> iter, boolean wantDirs, boolean fullInventory) {
this.orgIter = iter;
this.mc = mc;
this.wantDirs = wantDirs;
this.fullInventory = fullInventory;
this.next = nextFilteredFile();
}

public boolean hasNext() {
next = nextFilteredFile();
return (next != null);
}

public MFile next() {
if (next == null)
throw new NoSuchElementException();
return next;
final MFile mFile = next;
next = nextFilteredFile();
return mFile;
}

public void remove() {
Expand Down
6 changes: 3 additions & 3 deletions cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ public ResponseInputStream<GetObjectResponse> getInputStream() {

@Override
public void writeToStream(OutputStream outputStream) throws IOException {
ResponseInputStream<GetObjectResponse> responseInputStream = getInputStream();

IO.copy(responseInputStream, outputStream);
try (ResponseInputStream<GetObjectResponse> responseInputStream = getInputStream()) {
IO.copy(responseInputStream, outputStream);
}
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions cdm/s3/src/test/java/thredds/filesystem/s3/TestControllerS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public static void setup() {

}

@Test
public void shouldReturnSameValueFromHasNext() throws URISyntaxException {
final CdmS3Uri uri = new CdmS3Uri("cdms3:thredds-test-data");
final MFileFilter filter = new WildcardMatchOnName("testData.nc");
final CollectionConfig collectionConfig = new CollectionConfig(uri.getBucket(), uri.toString(), true, filter, null);
final ControllerS3 controller = new ControllerS3();
final Iterator<MFile> iterator = controller.getInventoryTop(collectionConfig, false);

assertThat(iterator.hasNext()).isTrue();
assertThat(iterator.hasNext()).isTrue();
iterator.next();
assertThat(iterator.hasNext()).isFalse();
assertThat(iterator.hasNext()).isFalse();
}

//////////////////////
// getInventoryTop() tests
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@

@Category(NeedsExternalResource.class)
public class TestS3ExternalCompressionRead {
private static final String compressedObject = "cdms3:noaa-nexrad-level2?1991/07/20/KTLX/KTLX19910720_160529.gz";
private static final String fragment = "#delimiter=/";

@Test
public void testCompressedObjectRead() throws IOException {
String bucket = "noaa-nexrad-level2";
String key = "1991/07/20/KTLX/KTLX19910720_160529.gz";
String s3uri = "cdms3:" + bucket + "?" + key;
testCompressedObjectRead(compressedObject);
}

@Test
public void testCompressedObjectReadWithDelimiterFragment() throws IOException {
testCompressedObjectRead(compressedObject + fragment);
}

private static void testCompressedObjectRead(String s3uri) throws IOException {
System.setProperty(S3TestsCommon.AWS_REGION_PROP_NAME, S3TestsCommon.AWS_G16_REGION);
try (NetcdfFile ncfile = NetcdfFiles.open(s3uri)) {

Expand Down

0 comments on commit c4c7ea1

Please sign in to comment.