From 176d13c9f8f436f8aaf7c5946668cdd97713c7e7 Mon Sep 17 00:00:00 2001 From: pathikrit Date: Thu, 30 Nov 2017 10:40:39 -0500 Subject: [PATCH] capitalize defaults --- README.md | 8 ++- .../main/scala/better/files/Scanners.scala | 2 +- core/src/main/scala/better/files/Dsl.scala | 14 ++-- core/src/main/scala/better/files/File.scala | 70 +++++++++---------- .../main/scala/better/files/Implicits.scala | 28 ++++---- .../better/files/ReaderInputStream.scala | 2 +- .../src/main/scala/better/files/Scanner.scala | 10 +-- .../better/files/WriterOutputStream.scala | 2 +- .../src/main/scala/better/files/package.scala | 10 +-- 9 files changed, 75 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index b612b26c..385d6041 100644 --- a/README.md +++ b/README.md @@ -214,11 +214,14 @@ case class Person(name: String, age: Int) val person = new Person("Chris", 24) // Write -file.newOutputStream.buffered.asObjectOutputStream.serialize(obj).flush() +file.newOutputStream.asObjectOutputStream.serialize(obj).flush() // Read -val person2 = file.newInputStream.buffered.asObjectInputStream.readObject().asInstanceOf[Person] +val person2 = file.newInputStream.asObjectInputStream.readObject().asInstanceOf[Person] assert(person == person2) + +// Read using custom class loader: +file.newInputStream.asObjectInputStreamUsingClassLoader(classLoader = myClassLoader).readObject().asInstanceOf[Person] ``` The above can be simply written as: @@ -460,6 +463,7 @@ val zipFile = File("countries.zip").zipIn(file"usa.txt", file"russia.txt") val someTempZipFile: File = directory.zip() val someTempDir: File = zipFile.unzip() assert(directory === someTempDir) +``` GZIP handling: ```scala diff --git a/benchmarks/src/main/scala/better/files/Scanners.scala b/benchmarks/src/main/scala/better/files/Scanners.scala index 791e6039..b8536001 100644 --- a/benchmarks/src/main/scala/better/files/Scanners.scala +++ b/benchmarks/src/main/scala/better/files/Scanners.scala @@ -130,7 +130,7 @@ class CharBufferScanner(reader: BufferedReader) extends AbstractScanner(reader) * Scanner using https://github.com/williamfiset/FastJavaIO */ class FastJavaIOScanner(reader: BufferedReader) extends AbstractScanner(reader) { - protected def is: java.io.InputStream = new org.apache.commons.io.input.ReaderInputStream(reader, defaultCharset) + protected def is: java.io.InputStream = new org.apache.commons.io.input.ReaderInputStream(reader, DefaultCharset) private[this] val fastReader = new fastjavaio.InputReader(is) diff --git a/core/src/main/scala/better/files/Dsl.scala b/core/src/main/scala/better/files/Dsl.scala index b898579d..864622da 100644 --- a/core/src/main/scala/better/files/Dsl.scala +++ b/core/src/main/scala/better/files/Dsl.scala @@ -39,19 +39,19 @@ object Dsl { def /(f: File => File): File = f(file) - def <<(line: String)(implicit charset: Charset = defaultCharset): file.type = + def <<(line: String)(implicit charset: Charset = DefaultCharset): file.type = file.appendLines(line)(charset) - def >>:(line: String)(implicit charset: Charset = defaultCharset): file.type = + def >>:(line: String)(implicit charset: Charset = DefaultCharset): file.type = file.appendLines(line)(charset) - def <(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = defaultCharset): file.type = + def <(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = DefaultCharset): file.type = file.write(text)(openOptions, charset) - def `>:`(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = defaultCharset): file.type = + def `>:`(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = DefaultCharset): file.type = file.write(text)(openOptions, charset) - def `!`(implicit charset: Charset = defaultCharset): String = + def `!`(implicit charset: Charset = DefaultCharset): String = file.contentAsString(charset) def `===`(that: File): Boolean = @@ -147,10 +147,10 @@ object Dsl { def stat(file: File): PosixFileAttributes = file.posixAttributes - def unzip(zipFile: File)(destination: File)(implicit charset: Charset = defaultCharset): destination.type = + def unzip(zipFile: File)(destination: File)(implicit charset: Charset = DefaultCharset): destination.type = zipFile.unzipTo(destination)(charset) - def zip(files: File*)(destination: File, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = defaultCharset): destination.type = + def zip(files: File*)(destination: File, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = DefaultCharset): destination.type = destination.zipIn(files.iterator, compressionLevel)(charset) def ungzip(gzipFile: File)(destination: File): File = diff --git a/core/src/main/scala/better/files/File.scala b/core/src/main/scala/better/files/File.scala index 931efff4..f6954d48 100644 --- a/core/src/main/scala/better/files/File.scala +++ b/core/src/main/scala/better/files/File.scala @@ -136,7 +136,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * Create this file. If it exists, don't do anything * * @param asDirectory If you want this file to be created as a directory instead, set this to true (false by default) - * @param createParents If you also want all the parents to be created from root to this file (false by defailt) + * @param createParents If you also want all the parents to be created from root to this file (false by default) * @param attributes * @param linkOptions * @return @@ -235,7 +235,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge this } - def chars(implicit charset: Charset = defaultCharset): Iterator[Char] = + def chars(implicit charset: Charset = DefaultCharset): Iterator[Char] = newBufferedReader(charset).chars //TODO: ManagedResource here? /** @@ -245,7 +245,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param charset * @return all lines in this file */ - def lines(implicit charset: Charset = defaultCharset): Traversable[String] = + def lines(implicit charset: Charset = DefaultCharset): Traversable[String] = Files.readAllLines(path, charset).asScala /** @@ -256,13 +256,13 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param charset * @return */ - def lineIterator(implicit charset: Charset = defaultCharset): Iterator[String] = + def lineIterator(implicit charset: Charset = DefaultCharset): Iterator[String] = Files.lines(path, charset).toAutoClosedIterator - def tokens(splitter: StringSplitter = StringSplitter.default)(implicit charset: Charset = defaultCharset): Iterator[String] = + def tokens(splitter: StringSplitter = StringSplitter.Default)(implicit charset: Charset = DefaultCharset): Iterator[String] = newBufferedReader(charset).tokens(splitter) - def contentAsString(implicit charset: Charset = defaultCharset): String = + def contentAsString(implicit charset: Charset = DefaultCharset): String = new String(byteArray, charset) def printLines(lines: TraversableOnce[_])(implicit openOptions: File.OpenOptions = File.OpenOptions.append): this.type = { @@ -277,18 +277,18 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param charset * @return */ - def appendLines(lines: String*)(implicit charset: Charset = defaultCharset): this.type = { + def appendLines(lines: String*)(implicit charset: Charset = DefaultCharset): this.type = { Files.write(path, lines.asJava, charset, File.OpenOptions.append: _*) this } - def appendLine(line: String = "")(implicit charset: Charset = defaultCharset): this.type = + def appendLine(line: String = "")(implicit charset: Charset = DefaultCharset): this.type = appendLines(line)(charset) - def append(text: String)(implicit charset: Charset = defaultCharset): this.type = + def append(text: String)(implicit charset: Charset = DefaultCharset): this.type = appendByteArray(text.getBytes(charset)) - def appendText(text: String)(implicit charset: Charset = defaultCharset): this.type = + def appendText(text: String)(implicit charset: Charset = DefaultCharset): this.type = append(text)(charset) def appendByteArray(bytes: Array[Byte]): this.type = { @@ -315,13 +315,13 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge this } - def write(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = defaultCharset): this.type = + def write(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = DefaultCharset): this.type = writeByteArray(text.getBytes(charset))(openOptions) - def writeText(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = defaultCharset): this.type = + def writeText(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = DefaultCharset): this.type = write(text)(openOptions, charset) - def overwrite(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = defaultCharset): this.type = + def overwrite(text: String)(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = DefaultCharset): this.type = write(text)(openOptions, charset) def newRandomAccess(mode: File.RandomAccessMode = File.RandomAccessMode.read): RandomAccessFile = @@ -330,16 +330,16 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge def randomAccess(mode: File.RandomAccessMode = File.RandomAccessMode.read): ManagedResource[RandomAccessFile] = newRandomAccess(mode).autoClosed //TODO: Mode enum? - def newBufferedReader(implicit charset: Charset = defaultCharset): BufferedReader = + def newBufferedReader(implicit charset: Charset = DefaultCharset): BufferedReader = Files.newBufferedReader(path, charset) - def bufferedReader(implicit charset: Charset = defaultCharset): ManagedResource[BufferedReader] = + def bufferedReader(implicit charset: Charset = DefaultCharset): ManagedResource[BufferedReader] = newBufferedReader(charset).autoClosed - def newBufferedWriter(implicit charset: Charset = defaultCharset, openOptions: File.OpenOptions = File.OpenOptions.default): BufferedWriter = + def newBufferedWriter(implicit charset: Charset = DefaultCharset, openOptions: File.OpenOptions = File.OpenOptions.default): BufferedWriter = Files.newBufferedWriter(path, charset, openOptions: _*) - def bufferedWriter(implicit charset: Charset = defaultCharset, openOptions: File.OpenOptions = File.OpenOptions.default): ManagedResource[BufferedWriter] = + def bufferedWriter(implicit charset: Charset = DefaultCharset, openOptions: File.OpenOptions = File.OpenOptions.default): ManagedResource[BufferedWriter] = newBufferedWriter(charset, openOptions).autoClosed def newFileReader: FileReader = @@ -385,10 +385,10 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge def digestInputStream(digest: MessageDigest)(implicit openOptions: File.OpenOptions = File.OpenOptions.default): ManagedResource[DigestInputStream] = newDigestInputStream(digest)(openOptions).autoClosed - def newScanner(splitter: StringSplitter = StringSplitter.default)(implicit charset: Charset = defaultCharset): Scanner = + def newScanner(splitter: StringSplitter = StringSplitter.Default)(implicit charset: Charset = DefaultCharset): Scanner = Scanner(newBufferedReader(charset), splitter) - def scanner(splitter: StringSplitter = StringSplitter.default)(implicit charset: Charset = defaultCharset): ManagedResource[Scanner] = + def scanner(splitter: StringSplitter = StringSplitter.Default)(implicit charset: Charset = DefaultCharset): ManagedResource[Scanner] = newScanner(splitter)(charset).autoClosed def newOutputStream(implicit openOptions: File.OpenOptions = File.OpenOptions.default): OutputStream = @@ -397,28 +397,28 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge def outputStream(implicit openOptions: File.OpenOptions = File.OpenOptions.default): ManagedResource[OutputStream] = newOutputStream(openOptions).autoClosed - def newZipOutputStream(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = defaultCharset): ZipOutputStream = + def newZipOutputStream(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = DefaultCharset): ZipOutputStream = new ZipOutputStream(newOutputStream(openOptions), charset) - def zipInputStream(implicit charset: Charset = defaultCharset): ManagedResource[ZipInputStream] = + def zipInputStream(implicit charset: Charset = DefaultCharset): ManagedResource[ZipInputStream] = newZipInputStream(charset).autoClosed - def newZipInputStream(implicit charset: Charset = defaultCharset): ZipInputStream = + def newZipInputStream(implicit charset: Charset = DefaultCharset): ZipInputStream = new ZipInputStream(newFileInputStream.buffered, charset) - def zipOutputStream(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = defaultCharset): ManagedResource[ZipOutputStream] = + def zipOutputStream(implicit openOptions: File.OpenOptions = File.OpenOptions.default, charset: Charset = DefaultCharset): ManagedResource[ZipOutputStream] = newZipOutputStream(openOptions, charset).autoClosed - def newGzipOutputStream(bufferSize: Int = defaultBufferSize, syncFlush: Boolean = false, append: Boolean = false): GZIPOutputStream = + def newGzipOutputStream(bufferSize: Int = DefaultBufferSize, syncFlush: Boolean = false, append: Boolean = false): GZIPOutputStream = new GZIPOutputStream(newFileOutputStream(append), bufferSize, syncFlush) - def gzipOutputStream(bufferSize: Int = defaultBufferSize, syncFlush: Boolean = false, append: Boolean = false): ManagedResource[GZIPOutputStream] = + def gzipOutputStream(bufferSize: Int = DefaultBufferSize, syncFlush: Boolean = false, append: Boolean = false): ManagedResource[GZIPOutputStream] = newGzipOutputStream(bufferSize = bufferSize, syncFlush = syncFlush, append = append).autoClosed - def newGzipInputStream(bufferSize: Int = defaultBufferSize): GZIPInputStream = + def newGzipInputStream(bufferSize: Int = DefaultBufferSize): GZIPInputStream = new GZIPInputStream(newFileInputStream, bufferSize) - def gzipInputStream(bufferSize: Int = defaultBufferSize): ManagedResource[GZIPInputStream] = + def gzipInputStream(bufferSize: Int = DefaultBufferSize): ManagedResource[GZIPInputStream] = newGzipInputStream(bufferSize).autoClosed def newFileChannel(implicit openOptions: File.OpenOptions = File.OpenOptions.default, attributes: File.Attributes = File.Attributes.default): FileChannel = @@ -938,7 +938,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param destination The destination file; Creates this if it does not exists * @return The destination zip file */ - def zipTo(destination: File, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = defaultCharset): destination.type = { + def zipTo(destination: File, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = DefaultCharset): destination.type = { val files = if (isDirectory) children else Iterator(this) destination.zipIn(files, compressionLevel)(charset) } @@ -948,7 +948,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * * @return the target directory */ - def zip(compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = defaultCharset): File = + def zip(compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(implicit charset: Charset = DefaultCharset): File = zipTo(destination = File.newTemporaryFile(prefix = name, suffix = ".zip"), compressionLevel)(charset) /** @@ -958,7 +958,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param zipFilter An optional param to reject or accept unzipping a file * @return The destination where contents are unzipped */ - def unzipTo(destination: File, zipFilter: ZipEntry => Boolean = _ => true)(implicit charset: Charset = defaultCharset): destination.type = { + def unzipTo(destination: File, zipFilter: ZipEntry => Boolean = _ => true)(implicit charset: Charset = DefaultCharset): destination.type = { for { zipFile <- new ZipFile(toJava, charset).autoClosed entry <- zipFile.entries().asScala if zipFilter(entry) @@ -973,14 +973,14 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param destinationDirectory destination folder; Creates this if it does not exist * @return The destination where contents are unzipped */ - def streamedUnzip(destinationDirectory: File = File.newTemporaryDirectory(name.stripSuffix(".zip")))(implicit charset: Charset = defaultCharset): destinationDirectory.type = { + def streamedUnzip(destinationDirectory: File = File.newTemporaryDirectory(name.stripSuffix(".zip")))(implicit charset: Charset = DefaultCharset): destinationDirectory.type = { for { zipIn <- zipInputStream(charset) } zipIn.mapEntries(_.extractTo(destinationDirectory, zipIn)).size destinationDirectory } - def unGzipTo(destination: File = File.newTemporaryFile(suffix = name.stripSuffix(".gz")), append: Boolean = false, bufferSize: Int = defaultBufferSize): destination.type = { + def unGzipTo(destination: File = File.newTemporaryFile(suffix = name.stripSuffix(".gz")), append: Boolean = false, bufferSize: Int = DefaultBufferSize): destination.type = { for { in <- gzipInputStream(bufferSize) out <- destination.createIfNotExists(createParents = true).fileOutputStream(append) @@ -993,7 +993,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param destination * @return */ - def gzipTo(destination: File = File.newTemporaryFile(suffix = name + ".gz"), bufferSize: Int = defaultBufferSize, syncFlush: Boolean = false, append: Boolean = false): destination.type = { + def gzipTo(destination: File = File.newTemporaryFile(suffix = name + ".gz"), bufferSize: Int = DefaultBufferSize, syncFlush: Boolean = false, append: Boolean = false): destination.type = { for { in <- fileInputStream out <- destination.createIfNotExists(createParents = true).gzipOutputStream(bufferSize = bufferSize, syncFlush = syncFlush, append = append) @@ -1010,7 +1010,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * @param charset * @return this */ - def zipIn(files: Files, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(charset: Charset = defaultCharset): this.type = { + def zipIn(files: Files, compressionLevel: Int = Deflater.DEFAULT_COMPRESSION)(charset: Charset = DefaultCharset): this.type = { for { output <- newZipOutputStream(File.OpenOptions.default, charset).withCompressionLevel(compressionLevel).autoClosed input <- files @@ -1025,7 +1025,7 @@ class File private(val path: Path)(implicit val fileSystem: FileSystem = path.ge * * @return the zip file */ - def unzip(zipFilter: ZipEntry => Boolean = _ => true)(implicit charset: Charset = defaultCharset): File = + def unzip(zipFilter: ZipEntry => Boolean = _ => true)(implicit charset: Charset = DefaultCharset): File = unzipTo(destination = File.newTemporaryDirectory(name.stripSuffix(".zip")), zipFilter)(charset) /** diff --git a/core/src/main/scala/better/files/Implicits.scala b/core/src/main/scala/better/files/Implicits.scala index 24fd3322..4fb627f8 100644 --- a/core/src/main/scala/better/files/Implicits.scala +++ b/core/src/main/scala/better/files/Implicits.scala @@ -55,7 +55,7 @@ trait Implicits { } implicit class InputStreamOps(in: InputStream) { - def pipeTo(out: OutputStream, bufferSize: Int = defaultBufferSize): out.type = + def pipeTo(out: OutputStream, bufferSize: Int = DefaultBufferSize): out.type = pipeTo(out, Array.ofDim[Byte](bufferSize)) /** @@ -71,7 +71,7 @@ trait Implicits { } } - def asString(closeStream: Boolean = true, bufferSize: Int = defaultBufferSize)(implicit charset: Charset = defaultCharset): String = { + def asString(closeStream: Boolean = true, bufferSize: Int = DefaultBufferSize)(implicit charset: Charset = DefaultCharset): String = { try { new ByteArrayOutputStream(bufferSize).autoClosed .map(pipeTo(_, bufferSize = bufferSize).toString(charset.displayName())) @@ -86,7 +86,7 @@ trait Implicits { def buffered(bufferSize: Int): BufferedInputStream = new BufferedInputStream(in, bufferSize) - def asGzipInputStream(bufferSize: Int = defaultBufferSize): GZIPInputStream = + def asGzipInputStream(bufferSize: Int = DefaultBufferSize): GZIPInputStream = new GZIPInputStream(in, bufferSize) /** @@ -94,7 +94,7 @@ trait Implicits { * @param bufferSize * @return */ - def asObjectInputStream(bufferSize: Int = defaultBufferSize): ObjectInputStream = + def asObjectInputStream(bufferSize: Int = DefaultBufferSize): ObjectInputStream = new ObjectInputStream(if (bufferSize <= 0) in else buffered(bufferSize)) /** @@ -105,7 +105,7 @@ trait Implicits { * @return A special ObjectInputStream that loads a class based on a specified ClassLoader rather than the default * This is useful in dynamic container environments. */ - def asObjectInputStreamUsingClassLoader(classLoader: ClassLoader = getClass.getClassLoader, bufferSize: Int = defaultBufferSize): ObjectInputStream = + def asObjectInputStreamUsingClassLoader(classLoader: ClassLoader = getClass.getClassLoader, bufferSize: Int = DefaultBufferSize): ObjectInputStream = new ObjectInputStream(if (bufferSize <= 0) in else buffered(bufferSize)) { override protected def resolveClass(objectStreamClass: ObjectStreamClass): Class[_] = try { @@ -126,10 +126,10 @@ trait Implicits { } } - def reader(implicit charset: Charset = defaultCharset): InputStreamReader = + def reader(implicit charset: Charset = DefaultCharset): InputStreamReader = new InputStreamReader(in, charset) - def lines(implicit charset: Charset = defaultCharset): Iterator[String] = + def lines(implicit charset: Charset = DefaultCharset): Iterator[String] = reader(charset).buffered.lines().toAutoClosedIterator def bytes: Iterator[Byte] = @@ -143,16 +143,16 @@ trait Implicits { def buffered(bufferSize: Int): BufferedOutputStream = new BufferedOutputStream(out, bufferSize) - def asGzipOutputStream(bufferSize: Int = defaultBufferSize, syncFlush: Boolean = false): GZIPOutputStream = + def asGzipOutputStream(bufferSize: Int = DefaultBufferSize, syncFlush: Boolean = false): GZIPOutputStream = new GZIPOutputStream(out, bufferSize, syncFlush) - def writer(implicit charset: Charset = defaultCharset): OutputStreamWriter = + def writer(implicit charset: Charset = DefaultCharset): OutputStreamWriter = new OutputStreamWriter(out, charset) def printWriter(autoFlush: Boolean = false): PrintWriter = new PrintWriter(out, autoFlush) - def write(bytes: Iterator[Byte], bufferSize: Int = defaultBufferSize): out.type = { + def write(bytes: Iterator[Byte], bufferSize: Int = DefaultBufferSize): out.type = { bytes.grouped(bufferSize).foreach(buffer => out.write(buffer.toArray)) out.flush() out @@ -166,7 +166,7 @@ trait Implicits { * @param bufferSize * @return */ - def asObjectOutputStream(bufferSize: Int = defaultBufferSize): ObjectOutputStream = + def asObjectOutputStream(bufferSize: Int = DefaultBufferSize): ObjectOutputStream = new ObjectOutputStream(if (bufferSize <= 0) out else buffered(bufferSize)) } @@ -181,7 +181,7 @@ trait Implicits { def buffered: BufferedReader = new BufferedReader(reader) - def toInputStream(implicit charset: Charset = defaultCharset): InputStream = + def toInputStream(implicit charset: Charset = DefaultCharset): InputStream = new ReaderInputStream(reader)(charset) } @@ -189,7 +189,7 @@ trait Implicits { def chars: Iterator[Char] = reader.autoClosed.flatMap(res => eofReader(res.read()).map(_.toChar)) - def tokens(splitter: StringSplitter = StringSplitter.default): Iterator[String] = + def tokens(splitter: StringSplitter = StringSplitter.Default): Iterator[String] = reader.lines().toAutoClosedIterator.flatMap(splitter.split) } @@ -197,7 +197,7 @@ trait Implicits { def buffered: BufferedWriter = new BufferedWriter(writer) - def outputstream(implicit charset: Charset = defaultCharset): OutputStream = + def outputstream(implicit charset: Charset = DefaultCharset): OutputStream = new WriterOutputStream(writer)(charset) } diff --git a/core/src/main/scala/better/files/ReaderInputStream.scala b/core/src/main/scala/better/files/ReaderInputStream.scala index f9b792cc..95b40300 100644 --- a/core/src/main/scala/better/files/ReaderInputStream.scala +++ b/core/src/main/scala/better/files/ReaderInputStream.scala @@ -12,7 +12,7 @@ import scala.annotation.tailrec */ class ReaderInputStream(reader: Reader, encoder: CharsetEncoder, bufferSize: Int) extends InputStream { - def this(reader: Reader, bufferSize: Int = defaultBufferSize)(implicit charset: Charset = defaultCharset) = + def this(reader: Reader, bufferSize: Int = DefaultBufferSize)(implicit charset: Charset = DefaultCharset) = this(reader = reader, encoder = charset.newEncoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE), bufferSize = bufferSize) /** diff --git a/core/src/main/scala/better/files/Scanner.scala b/core/src/main/scala/better/files/Scanner.scala index be6ebb3f..036ca379 100644 --- a/core/src/main/scala/better/files/Scanner.scala +++ b/core/src/main/scala/better/files/Scanner.scala @@ -22,19 +22,19 @@ trait Scanner extends Iterator[String] with AutoCloseable { object Scanner { def apply(str: String): Scanner = - Scanner(str, StringSplitter.default) + Scanner(str, StringSplitter.Default) def apply(str: String, splitter: StringSplitter): Scanner = Scanner(new StringReader(str), splitter) def apply(reader: Reader): Scanner = - Scanner(reader, StringSplitter.default) + Scanner(reader, StringSplitter.Default) def apply(reader: Reader, splitter: StringSplitter): Scanner = Scanner(new LineNumberReader(reader.buffered), splitter) - def apply(inputStream: InputStream)(implicit charset: Charset = defaultCharset): Scanner = - Scanner(inputStream, StringSplitter.default)(charset) + def apply(inputStream: InputStream)(implicit charset: Charset = DefaultCharset): Scanner = + Scanner(inputStream, StringSplitter.Default)(charset) def apply(inputStream: InputStream, splitter: StringSplitter)(implicit charset: Charset): Scanner = Scanner(inputStream.reader(charset), splitter) @@ -130,7 +130,7 @@ trait StringSplitter { def split(s: String): TraversableOnce[String] } object StringSplitter { - val default = StringSplitter.anyOf(" \t\t\n\r") + val Default = StringSplitter.anyOf(" \t\t\n\r") /** * Split string on this character diff --git a/core/src/main/scala/better/files/WriterOutputStream.scala b/core/src/main/scala/better/files/WriterOutputStream.scala index 80cd5fc8..2ec18b00 100644 --- a/core/src/main/scala/better/files/WriterOutputStream.scala +++ b/core/src/main/scala/better/files/WriterOutputStream.scala @@ -23,7 +23,7 @@ class WriterOutputStream(writer: Writer, decoder: CharsetDecoder, bufferSize: In */ private[this] val decoderIn = ByteBuffer.allocate(bufferSize>>4) - def this(writer: Writer, bufferSize: Int = defaultBufferSize, flushImmediately: Boolean = false)(implicit charset: Charset = defaultCharset) = + def this(writer: Writer, bufferSize: Int = DefaultBufferSize, flushImmediately: Boolean = false)(implicit charset: Charset = DefaultCharset) = this(writer = writer, decoder = charset.newDecoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE).replaceWith("?"), bufferSize = bufferSize, flushImmediately = flushImmediately) override def write(b: Array[Byte], off: Int, len: Int) = { diff --git a/core/src/main/scala/better/files/package.scala b/core/src/main/scala/better/files/package.scala index bef8c1ed..a739cb9a 100644 --- a/core/src/main/scala/better/files/package.scala +++ b/core/src/main/scala/better/files/package.scala @@ -12,14 +12,14 @@ package object files extends Implicits { * Default array buffer size * Seems like a good value used by JDK: (see: java.io.BufferedInputStream.DEFAULT_BUFFER_SIZE) */ - val defaultBufferSize = 8192 + val DefaultBufferSize = 8192 /** - * The default charset used by better-files - * Note: It uses java.net.charset.Charset.defaultCharset() in general but if the default supports byte-order markers, + * The Default charset used by better-files + * Note: It uses java.net.charset.Charset.DefaultCharset() in general but if the Default supports byte-order markers, * it uses a more compliant version than the JDK one (see: https://github.com/pathikrit/better-files/issues/107) */ - val defaultCharset: Charset = + val DefaultCharset: Charset = UnicodeCharset(Charset.defaultCharset()) val EOF = StreamTokenizer.TT_EOF @@ -31,7 +31,7 @@ package object files extends Implicits { * @param bufferSize * @return */ - def resourceAsStream(name: String, bufferSize: Int = defaultBufferSize): InputStream = + def resourceAsStream(name: String, bufferSize: Int = DefaultBufferSize): InputStream = currentClassLoader().getResourceAsStream(name).buffered(bufferSize) // Some utils: