Package nbbrd.io
Class Resource
- java.lang.Object
-
- nbbrd.io.Resource
-
public class Resource extends Object
- Author:
- Philippe Charles
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceResource.Loader<K>static interfaceResource.Storer<K>
-
Constructor Summary
Constructors Constructor Description Resource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseBoth(@Nullable Closeable first, @Nullable Closeable second)voidensureClosed(@NonNull Throwable exception, @Nullable Closeable closeable)@NonNull Optional<File>getFile(@NonNull Path path)Returns aFileobject representing this path.@NonNull Optional<InputStream>getResourceAsStream(@NonNull Class<?> type, @NonNull String name)voidprocess(@NonNull URI uri, @NonNull IOConsumer<? super Path> action)Process a classpath resource as a Path.
-
-
-
Method Detail
-
getFile
public @NonNull Optional<File> getFile(@NonNull Path path)
Returns aFileobject representing this path. Where thisPathis associated with the default provider, then this method is equivalent to returning aFileobject constructed with theStringrepresentation of this path.If this path was created by invoking the
FiletoPathmethod then there is no guarantee that theFileobject returned by this method isequalto the originalFile.- Parameters:
path-- Returns:
- an optional
Fileobject representing this path if associated with the default provider
-
getResourceAsStream
public @NonNull Optional<InputStream> getResourceAsStream(@NonNull Class<?> type, @NonNull String name)
-
closeBoth
public void closeBoth(@Nullable Closeable first, @Nullable Closeable second) throws IOException
- Throws:
IOException
-
process
public void process(@NonNull URI uri, @NonNull IOConsumer<? super Path> action) throws IOException
Process a classpath resource as a Path.- Parameters:
uri-action-- Throws:
IOException- See Also:
- https://stackoverflow.com/a/36021165
-
-