paths


License

License

GroupId

GroupId

org.hammerlab
ArtifactId

ArtifactId

paths_2.12
Last Version

Last Version

1.6.0
Release Date

Release Date

Type

Type

jar
Description

Description

paths
paths
Project URL

Project URL

https://github.com/hammerlab/path-utils
Project Organization

Project Organization

org.hammerlab
Source Code Management

Source Code Management

https://github.com/hammerlab/path-utils

Download paths_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/org.hammerlab/paths_2.12/ -->
<dependency>
    <groupId>org.hammerlab</groupId>
    <artifactId>paths_2.12</artifactId>
    <version>1.6.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.hammerlab/paths_2.12/
implementation 'org.hammerlab:paths_2.12:1.6.0'
// https://jarcasting.com/artifacts/org.hammerlab/paths_2.12/
implementation ("org.hammerlab:paths_2.12:1.6.0")
'org.hammerlab:paths_2.12:jar:1.6.0'
<dependency org="org.hammerlab" name="paths_2.12" rev="1.6.0">
  <artifact name="paths_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.hammerlab', module='paths_2.12', version='1.6.0')
)
libraryDependencies += "org.hammerlab" % "paths_2.12" % "1.6.0"
[org.hammerlab/paths_2.12 "1.6.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.7
com.github.alexarchambault : case-app_2.12 jar 2.0.0-M3
commons-io : commons-io jar 2.5
org.hammerlab : types_2.12 jar 1.4.0
org.clapper : grizzled-slf4j_2.12 jar 1.3.1

test (3)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.4
org.hammerlab.test : base_2.12 jar 1.0.3
org.slf4j : slf4j-log4j12 jar 1.7.21

Project Modules

There are no modules declared in this project.

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:

import hammerlab.path._
val path = Path("")    // current directory; URIs and Strings accepted
path.exists            // true
path / 'src list       // list children of src dir: Iterator(src/main,src/test)

Examples

Existence / Child-resolution

val src = path / 'src  // "src" subdir
src.exists             // true
path / 'foo exists     // false

Directory-traversal

(path / 'src / 'test walk) filter (_.isFile)
// Iterator(
//   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:

  • def inputStream: InputStream
  • def outputStream: OutputStream
  • def read: String
  • def readBytes: Array[Byte]
  • def write(String)
  • def writeLines(Iterable[String])
  • def lines: Iterator[String]
  • def size: Long

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:

wget -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
sbt console
import hammerlab.path._
val index = Path("gs://gcp-public-data-landsat/index.csv.gz")

index.exists  // true
index.size    // 476118237

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

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

Paths.get(uri)
// java.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)

org.hammerlab

Hammer Lab

We're a lab working to understand and improve the immune response to cancer

Versions

Version
1.6.0
1.5.0
1.4.0
1.3.1
1.3.0
1.2.0
1.1.0
1.0.2
1.0.1
1.0.0