hammerlab/path-utils

Name: path-utils

Owner: Hammer Lab

Description: Scala convenience-wrapper for java.nio.file.Path

Created: 2017-04-01 23:24:08.0

Updated: 2017-04-03 16:42:16.0

Pushed: 2018-01-15 00:25:35.0

Homepage: null

Size: 46

Language: Scala

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

paths

Serializable wrapper for java.nio.file.Path

Build Status Coverage Status

org.hammerlab:paths_2.11 on Maven Central org.hammerlab:paths_2.12 on Maven Central

Filesystem-path convenience methods and bug-fixes:

rt hammerlab.path._
path = Path("")    // current directory; URIs and Strings accepted
.exists            // true
 / 'src list       // list children of src dir: Iterator(src/main,src/test)
Examples
Existence / Child-resolution
src = path / 'src  // "src" subdir
exists             // true
 / 'foo exists     // false
Directory-traversal
h / 'src / 'test walk) filter (_.isFile)
terator(
 src/test/resources/log4j.properties,
 src/test/resources/META-INF/services/java.nio.file.spi.FileSystemProvider,
 src/test/scala/org/hammerlab/paths/PathTest.scala

IO

Self-explanatory methods:

Serializability

Paths are Serializable, delegating to the SerializablePath proxy, which serializes them as URIs.

JSR203 FileSystemProvider improvements

Interacting with Java NIO FileSystemProviders from Scala is broken; see scala/bug#10247.

Paths from this repo have hooks to lazily initialize and tweak the FileSystemProvider initialization code to resolve these problems; see FileSystems.scala.

There is also fix for a missing newByteChannel implementation in the JRE's default implementation of JarFileSystemProvider; use of Paths replaces it with a custom JarFileSystemProvider with this issue resolved.

As an example, try downloading the Google Cloud Storage NIO connector JAR, and querying for the existence and size of a public file:

 -O lib/gcs-nio.jar http://search.maven.org/remotecontent?filepath=com/google/cloud/google-cloud-nio/0.28.0-alpha/google-cloud-nio-0.28.0-alpha-shaded.jar
console
rt hammerlab.path._
index = Path("gs://gcp-public-data-landsat/index.csv.gz")

x.exists  // true
x.size    // 476118237

In contrast, trying the equivalent using vanilla Java NIO paths fails:

rt java._, nio.file._, net._
uri = new URI("gs://gcp-public-data-landsat/index.csv.gz")

s.get(uri)
ava.nio.file.FileSystemNotFoundException: Provider "gs" not installed
 at java.nio.file.Paths.get(Paths.java:147)
 ... 42 elided

(test this in a fresh sbt console, as initializing a hammerlab Path fixes the providers in that JVM)


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.