Skip to content

Commit

Permalink
Merge branch 'master' into 2.10.x
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/scala/scalax/io/LongTraversableLike.scala
	core/src/main/scala/scalax/io/traversable/ByteResourceTraversable.scala
	core/src/main/scala/scalax/io/traversable/Sliceable.scala
	project/Build.scala
  • Loading branch information
Jesse Eichar committed May 31, 2012
2 parents bde691e + 8b5467d commit 15fc046
Show file tree
Hide file tree
Showing 186 changed files with 796 additions and 823 deletions.
10 changes: 5 additions & 5 deletions core/exception-handling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ object ExceptionHandling {
* is also known so a default value can be provided.
* </p><p>
* This pattern can be quite tricky because the internals of how Scala-IO works needs to be known.
* For example if providing a default for slurpString then one must know that bytes must be
* returned as the default rather than a string.
* For example if providing a default for slurpString then one must know that bytes must be
* returned as the default rather than a string.
* </p>
* <p>
* Also if the scala-io implementation changes the code could break. Defaults work better when
* working with acquireAndGet or acquireFor
* working with acquireAndGet or acquireFor
* </p>
*/
def returnDefaultValueOnFailure {
Expand Down Expand Up @@ -113,15 +113,15 @@ object ExceptionHandling {
override def openErrorHandler[A, U](f: A => U, openException: Throwable): Option[U] = {
f match {
case f: FunctionWithDefault[_, U] =>
// perform logging
// perform logging
Some(f.defaultValue)
case _ => super.openErrorHandler(f, openException)
}
}
override def errorHandler[A, U](f: A => U, accessResult: Either[Throwable, U], closingExceptions: List[Throwable]): U = {
f match {
case f: FunctionWithDefault[_, U] =>
// perform logging
// perform logging
f.defaultValue
case _ => super.errorHandler(f, accessResult, closingExceptions)
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/scalax/io/ByteBlock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ trait ByteBlock {
def apply(i: Int): Byte
def size: Int
def force:ByteBlock = new ByteBlock {
val data = self.toSeq
val data = self.toSeq
override val force = this
override val toSeq = data
override val toIterator = data.toIterator
val size = data.size
def apply(i:Int) = data(i)
}

def toSeq = toIterator.foldLeft(Seq[Byte]())((acc,next) => acc :+ next)
def toIterator = new Iterator[Byte] {
private[this] val _size = self.size
Expand All @@ -21,7 +21,7 @@ trait ByteBlock {
pos += 1
self.apply(pos - 1)
}
def hasNext =
def hasNext =
pos < _size
}
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala/scalax/io/CloseAction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ trait CloseAction[-A] {
* @param other an action to ''prepend'' to this action
* @return an action consisting of first executing ''other'' then ''this''
*/
def +:[B <: A](other:CloseAction[B]):CloseAction[B] = other match {
def +:[B <: A](other:CloseAction[B]):CloseAction[B] = other match {
case Noop => this
case _ => new Prepend(other,this)
}
Expand All @@ -83,7 +83,7 @@ trait CloseAction[-A] {
* @param other an action to ''append'' to this action
* @return an action consisting of first executing ''this'' then ''other''
*/
def :+[B <: A](other:CloseAction[B]):CloseAction[B] = other match {
def :+[B <: A](other:CloseAction[B]):CloseAction[B] = other match {
case Noop => this
case _ => new Append(other,this)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalax/io/CloseableIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ private[io] class InitIterator[@specialized(Byte) +A](iter:CloseableIterator[A])
}

def doClose = iter.close()
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/scalax/io/Codec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/scalax/io/CompositeIterable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ class CompositeIterable[A](builderIterators: Seq[() => Iterator[A]]) {
}
}
}
}
}
12 changes: 6 additions & 6 deletions core/src/main/scala/scalax/io/Input.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import java.io.{InputStream, File}
trait Input {
/**
* Get the Resource context that configures how the underlying resource is accessed
*
*
* @return the associated ResourceContext
*/
def context:ResourceContext
Expand All @@ -54,19 +54,19 @@ trait Input {
* @return an non-strict traversable over all the bytes
*/
def bytes : LongTraversable[Byte]

/**
* Read the input as blocks of bytes. This method should be avoided unless the maximum performance is
* absolutely required because bytes provides very good performance and is a better API for most applications.
*
*
* However since it better reflects how data is read with most input sources (like InputStreams and ReadableByteChannels);
* blocks is slightly more performance than bytes and therefore
* can be used when performance is the most important consideration.
*
*
* @param blockSize block size can optionally be specified but the default is normally acceptable.
*/
def blocks(blockSize: Option[Int] = None): LongTraversable[ByteBlock]

/**
* Obtains a Traversable for conveniently processing the file as Ints.
*
Expand Down Expand Up @@ -134,5 +134,5 @@ trait Input {
* The codec representing the desired encoding of the characters
*/
def slurpString(implicit codec: Codec = Codec.default) = new String(byteArray, codec.name)

}
30 changes: 15 additions & 15 deletions core/src/main/scala/scalax/io/JavaConverters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ object JavaConverters {
*/
implicit def asOutputConverter[B](src:B)(implicit converter:AsOutputConverter[B]) =
new AsOutput(converter.toOutput(src))

/**
* Used by the [[scalax.io.Output]] object for converting an arbitrary object to an Output Object
*
Expand All @@ -151,13 +151,13 @@ object JavaConverters {
trait AsOutputConverter[-A] {
def toOutput(t:A) : Output
}

/**
* contains several implementations of [[scalax.io.AsOutputConverter]]. They will be implicitly resolved allowing
* a user of the library to simple call A.asOutput and the converter will be found without the user needing to look up these classes
*/
object AsOutputConverter {

/**
* Converts a File to an Output object
*/
Expand All @@ -175,10 +175,10 @@ object JavaConverters {
* Converts a WritableByteChannel to an Output object
*/
implicit object WritableByteChannelConverter extends AsOutputConverter[WritableByteChannel]{
def toOutput(chan: WritableByteChannel) = Resource.fromWritableByteChannel(chan)
def toOutput(chan: WritableByteChannel) = Resource.fromWritableByteChannel(chan)
}
}

class AsBinaryReadChars(op: Codec => ReadChars) {
/** An object to an ReadChars object */
def asBinaryReadChars(implicit codec:Codec = Codec.default): ReadChars = op(codec)
Expand All @@ -192,7 +192,7 @@ object JavaConverters {
implicit def asReadCharsConverter[B](src:B)(implicit converter:AsBinaryReadCharsConverter[B]) =
new AsBinaryReadChars(codec => converter.toReadChars(src,codec))


/**
* Used by the [[scalax.io.ReadChars]] object for converting an arbitrary object to an ReadChars Object
*
Expand All @@ -201,7 +201,7 @@ object JavaConverters {
trait AsBinaryReadCharsConverter[-A] {
def toReadChars(t:A,codec:Codec) : ReadChars
}

/**
* contains several implementations of [[scalax.io.AsReadCharsConverterFromBinary]]. They will be implicitly resolved allowing
* a user of the library to simple call A.asBinaryReadChars and the converter will be found without the user needing to look up these classes
Expand Down Expand Up @@ -297,7 +297,7 @@ object JavaConverters {
implicit def asSeekableConverter[B](src:B)(implicit converter:AsSeekableConverter[B]) =
new AsSeekable(converter.toSeekable(src))


/**
* Used by the [[scalax.io.Seekable]] object for converting an arbitrary object to an Seekable Object
*
Expand All @@ -306,13 +306,13 @@ object JavaConverters {
trait AsSeekableConverter[-A] {
def toSeekable(t:A) : Seekable
}

/**
* contains several implementations of [[scalax.io.AsSeekableConverter]]. They will be implicitly resolved allowing
* a user of the library to simple call A.asSeekable and the converter will be found without the user needing to look up these classes
*/
object AsSeekableConverter {

/**
* Converts a File to an Seekable object
*/
Expand Down Expand Up @@ -351,7 +351,7 @@ object JavaConverters {
*/
implicit def asWriteCharsConverter[B](src:B)(implicit converter:AsBinaryWriteCharsConverter[B]) =
new AsBinaryWriteChars(codec => converter.toWriteChars(src,codec))

/**
* Used by the [[scalax.io.WriteChars]] object for converting an arbitrary object to an WriteChars Object
*
Expand All @@ -360,13 +360,13 @@ object JavaConverters {
trait AsBinaryWriteCharsConverter[-A] {
def toWriteChars(t:A,codec:Codec) : WriteChars
}

/**
* contains several implementations of [[scalax.io.AsWriteCharsConverter]]. They will be implicitly resolved allowing
* a user of the library to simple call A.asWriteChars and the converter will be found without the user needing to look up these classes
*/
object AsBinaryWriteCharsConverter {

/**
* Converts a File to an WriteChars object
*/
Expand Down Expand Up @@ -573,7 +573,7 @@ object JavaConverters {
def toUnmanagedReadChars(reader: Reader) = new unmanaged.ReaderResource(reader)
}
}

class AsUnmanagedBinaryWriteChars(op: (Codec) => WriteChars) {
/** An object to an WriteChars object */
def asUnmanagedBinaryWriteChars(implicit codec:Codec = Codec.default): WriteChars = op(codec)
Expand Down Expand Up @@ -644,4 +644,4 @@ object JavaConverters {
def toUnmanagedWriteChars(writer: Writer) = new unmanaged.WriterResource(writer)
}
}
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala/scalax/io/Line.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
Expand All @@ -25,7 +25,7 @@ object Line {
* It can detect N,R and RN line terminators
*/
case object Auto extends Terminator

abstract class SimpleTerminator(val sep:String) extends Terminator
/*
* The \n line terminator
Expand Down
26 changes: 13 additions & 13 deletions core/src/main/scala/scalax/io/LineTraversable.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
Expand All @@ -24,13 +24,13 @@ class LineTraversable(source: => CloseableIterator[Char], terminator: Terminator
def context = resourceContext
protected[io] def iterator = terminator match {
case Auto => new AutoCharIter(source,includeTerminator)
case t:SimpleTerminator if t.sep.size == 1 => new SingleCharIter(source, t.sep.head, includeTerminator)
case t:SimpleTerminator => new MultiCharIter(source, t.sep, includeTerminator)
case t:SimpleTerminator if t.sep.size == 1 => new SingleCharIter(source, t.sep.head, includeTerminator)
case t:SimpleTerminator => new MultiCharIter(source, t.sep, includeTerminator)
}
}

private[io] class SingleCharIter(private[this] val sourceIter: CloseableIterator[Char],
private[this] val term:Char,
private[io] class SingleCharIter(private[this] val sourceIter: CloseableIterator[Char],
private[this] val term:Char,
private[this] val includeTerm:Boolean) extends CloseableIterator[String] {
private[this] val sb = new StringBuilder

Expand All @@ -50,12 +50,12 @@ private[io] class SingleCharIter(private[this] val sourceIter: CloseableIterator
if(includeTerm) sb append term
sb.toString
}

def doClose = sourceIter.close()
}

private[io] class MultiCharIter(private[this] val sourceIter: CloseableIterator[Char],
private[this] val term:String,
private[io] class MultiCharIter(private[this] val sourceIter: CloseableIterator[Char],
private[this] val term:String,
private[this] val includeTerm:Boolean) extends CloseableIterator[String] {
private[this] val sb = new StringBuilder

Expand All @@ -79,12 +79,12 @@ private[io] class MultiCharIter(private[this] val sourceIter: CloseableIterator[
def doClose = sourceIter.close()
}

private[io] class AutoCharIter(private[this] val sourceIter: CloseableIterator[Char],
private[io] class AutoCharIter(private[this] val sourceIter: CloseableIterator[Char],
private[this] val includeTerm:Boolean) extends CloseableIterator[String] {

private[this] val sb = new StringBuilder
private[this] val iter = new CharBufferedIterator(sourceIter)
private[this] val iter = new CharBufferedIterator(sourceIter)

@inline
private[this] final def getc() = {
if(iter.hasNext) {
Expand All @@ -95,7 +95,7 @@ private[io] class AutoCharIter(private[this] val sourceIter: CloseableIterator[C
iter.next
"\r\n"
} else {
"\r"
"\r"
}
}
else {
Expand Down Expand Up @@ -139,4 +139,4 @@ private class CharBufferedIterator(private[this] val sourceIter: CloseableIterat
hdDefined = false
hd
} else sourceIter.next()
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/scalax/io/LongTraversable.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** / __/ __// _ | / / / _ | (c) 2009-2010, Jesse Eichar **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
Expand Down
Loading

0 comments on commit 15fc046

Please sign in to comment.