Skip to content

Commit

Permalink
Change MFiles.create to be Nonnull
Browse files Browse the repository at this point in the history
  • Loading branch information
tdrwenski committed Apr 26, 2023
1 parent c185740 commit e064e78
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
5 changes: 1 addition & 4 deletions cdm/core/src/main/java/thredds/inventory/MFileProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package thredds.inventory;

import java.io.IOException;
import javax.annotation.Nullable;

/**
* A Service Provider of {@link thredds.inventory.MFile}.
Expand All @@ -22,12 +21,10 @@ default boolean canProvide(String location) {
}

/**
* Create an {@link thredds.inventory.MFile} from a given location if it exists and is readable, otherwise return
* null.
* Create an {@link thredds.inventory.MFile} from a given location, the file may or may not exist
*
* @param location location of a file or .
* @return {@link thredds.inventory.MFile}
*/
@Nullable
MFile create(String location) throws IOException;
}
16 changes: 8 additions & 8 deletions cdm/core/src/main/java/thredds/inventory/MFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;
import java.util.ServiceLoader;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import thredds.filesystem.MFileOS;
Expand All @@ -22,14 +22,13 @@ public class MFiles {
private static final Logger logger = LoggerFactory.getLogger(NcmlReader.class);

/**
* Create an {@link thredds.inventory.MFile} from a given location if it exists and is readable, otherwise return
* null.
* Create an {@link thredds.inventory.MFile} from a given location, the file may or may not exist
*
* @param location location of file (local or remote) to be used to back the MFile object
* @return {@link thredds.inventory.MFile}
*/
@Nullable
public static MFile create(String location) {
@Nonnull
public static MFile create(@Nonnull String location) {
MFileProvider mFileProvider = null;

// look for dynamically loaded MFileProviders
Expand All @@ -40,12 +39,13 @@ public static MFile create(String location) {
}
}

MFile mfile = null;
try {
mfile = mFileProvider != null ? mFileProvider.create(location) : MFileOS.getExistingFile(location);
if (mFileProvider != null) {
return mFileProvider.create(location);
}
} catch (IOException ioe) {
logger.error("Error creating MFile at {}.", location, ioe);
}
return mfile;
return new MFileOS(location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AggDataset implements Comparable<AggDataset> {
private static final boolean debugOpenFile = false;
private static final boolean debugRead = false;

@Nullable
private final MFile mfile;
private final Set<Enhance> enhance; // used by Fmrc to read enhanced datasets
@Nullable
Expand Down Expand Up @@ -71,7 +72,7 @@ protected AggDataset(MFile mfile, @Nullable Object spiObject, @Nullable Element
protected AggDataset(String cacheLocation, String location, @Nullable String id,
@Nullable EnumSet<Enhance> wantEnhance, @Nullable ucar.nc2.util.cache.FileFactory reader,
@Nullable Object spiObject, @Nullable Element ncmlElem) {
this.mfile = MFiles.create(location); // may be null
this.mfile = location == null ? null : MFiles.create(location);
this.cacheLocation = cacheLocation;
this.id = id;
this.enhance = (wantEnhance == null) ? NetcdfDataset.getEnhanceNone() : wantEnhance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public boolean syncExtend() throws IOException {
public long getLastModified() {
if (location != null) {
MFile file = MFiles.create(location);
return file != null ? file.getLastModified() : 0;
return file.getLastModified();
} else {
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion cdm/s3/src/main/java/thredds/inventory/s3/MFileS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ public String getProtocol() {
return protocol;
}

@Nullable
@Override
public MFile create(String location) throws IOException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public boolean canProvide(String location) {
return location != null && location.contains(ext);
}

@Nullable
@Override
public MFile create(String location) throws IOException {
return new MFileZip(location);
Expand Down

0 comments on commit e064e78

Please sign in to comment.