raisercostin / jedi-io   0.60

Apache License 2.0 GitHub

Uniform, fluent access to files, urls and other resources API from java and scala.

Scala versions: 2.12 2.11 2.10

Jedi IO

Status

Download Build Status Codacy Badge codecov

Description

Scala uniform, fluent access to files, urls and other resources API. Fluent for java too.

Features

  • HierarchicalMultimap should be case insensitive and should have operations to: add/remove from map and contains
  • integrate apache commons vfs via Locations.vfs("...")
  • UrlLocation transparently manages
    • handle redirects
    • good RequestHeader defaults
    • reuse already opened HttpConnections
    • use proxy if using scalaj/http library
    • manage backpresure from server
      • [TODO] connection timeout temporarly
      • [TODO] maximum connections/ip-hostname? for a specified timeframe?
      • [TODO] delay between requests to same server
    • [TODO] non-blocking IO returning Future/Observable ?
  • Version and Etag that is changed if file is changed. A change version/tag doesn't warranty a change in file content.
  • Types of Locations
    • Abstract Locations
      • InputLocation - locations that can be read
      • OutputLocation - locations that can be written
      • InOutLocation - location that can be read/written
      • RelativeLocation - part of a location. Cannot be resolved to some content.
      • NavigableLocation - location for which you can find parent/childrens/descendants.
      • VersionedLocation - location trait with Version/Etag/UniqueId
    • Physical Locations
      • FileLocation - HasContent, NoChildren
      • FolderLocation - NoContent, HasChildren
      • MemoryLocation - read/write in memory content - useful for tests.
      • ClasspathLocation - InputLocation from classpath.
      • Stream Location - location from a InputStream. Might not be reopened.
      • TempLocation - location in the temporary file system.
      • UrlLocation - location from a url. Follows redirects if needed
      • VfsLocation - location based on Apache-Vfs library
      • ZipInputLocation - location around zip files
  • natural sorting for listing files
  • Operation Options
    • CopyOptions: copy metadata forced or optionally if exists
    • OperationMonitor: log warnings
  • Default copy should use links. If needed you can specify duplicateContent.

Usage

Samples

   //Reading from a file:
   Locations.file("/home/costin/myfile.txt").readContent

   //Copying a file to a new folder (and create parent folder if needed)
   Locations.file("/home/costin/myfile.txt").
   	copyTo(Locations.file("/home/costin/folder2/myfile2.txt").mkdirOnParentIfNecessary))

	//Copying a file to a new relative folder (and create parent folder if needed)
   Locations.file("/home/costin/myfile.txt").
   	copyTo(Locations.relative("folder3/myfile2.txt")))

   //read content from classpath
   val text = Locations.classpath("META-INF/maven/org.slf4j/slf4j-api/pom.properties").
   	readContentAsText.get

   //get a stream  from classpath
   val text = Locations.classpath("META-INF/maven/org.slf4j/slf4j-api/pom.properties").toInputStream

For more samples see LocationsTest.scala

Library

  • from sbt
libraryDependencies += "org.raisercostin" %% "jedi-io" % "0.18"
resolvers += "raisercostin repository" at "http://dl.bintray.com/raisercostin/maven"

Development

Projects that are using jedi-io:

sbt> release skip-tests

History

2017-12-06

  • Locations.fromString("content"):MemoryLocation

Backlog

Technology Selection

Hierarchical Map

A container of keys in form a.b.c is needed. The value could be multivalue eventually typed : Seq(value1,value2,value3). Given a container and a key prefix another container should be returned with partial keys prefix removed. A refereence to full key might be useful. A relativeKey concept might be useful? A save/load from hocon, yaml would be nice. A business wrapper around a Config should be easy to use.

Resources