本文整理汇总了Scala中java.io.Reader类的典型用法代码示例。如果您正苦于以下问题:Scala Reader类的具体用法?Scala Reader怎么用?Scala Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reader类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: CaseInsensitiveInputStream
//设置package包名称以及导入依赖的类
package io.github.nawforce.apexlink.utils
import java.io.{InputStream, InputStreamReader, Reader}
import org.antlr.v4.runtime.{ANTLRInputStream, IntStream}
class CaseInsensitiveInputStream(r: Reader, initialSize: Int, readChunkSize: Int)
extends ANTLRInputStream(r, initialSize, readChunkSize) {
//lazy is important here because need initiated data[], which is loaded in super class
private lazy val lowercaseData: Array[Char] = data.map(_.toLower)
def this(r: Reader) {
this(r, initialSize = 1024, readChunkSize = 1024)
}
def this(input: InputStream) {
this(new InputStreamReader(input), initialSize = 1024, readChunkSize = 1024)
}
override def LA(index: Int): Int = {
var i = index
if (i == 0) {
return 0
}
if (i < 0) {
i += 1
if ((p + i - 1) < 0) {
return IntStream.EOF
}
}
if ((p + i - 1) >= n) {
return IntStream.EOF
}
if (null != lowercaseData) {
lowercaseData(p + i - 1)
} else {
data(p + i - 1).toLower
}
}
def dump(): Unit = {
var i = 0
var value = 0
do {
value = LA(i)
i += 1
print(value.asInstanceOf[Char])
} while (value != IntStream.EOF)
}
}
开发者ID:nawforce,项目名称:ApexLink,代码行数:55,代码来源:CaseInsensitiveInputStream.scala
示例2: RamlModel
//设置package包名称以及导入依赖的类
package se.gigurra.ramlgen.core
import java.io.{File, Reader}
import org.raml.v2.api.model.v10.api.{Api => V10Model}
import org.raml.v2.api.model.v10.datamodel.TypeDeclaration
import org.raml.v2.api.model.v10.security.{SecurityScheme, SecuritySchemeRef}
import org.raml.v2.api.{RamlModelBuilder, RamlModelResult}
import scala.collection.JavaConversions._
val securitySchemas: Seq[SecurityScheme] = model.securitySchemes
///.. .. ..
// RAML is tooo huuuuge >P> Maybe I could generate code for a subset.. but types through security... that's a bigger problem :S
}
object RamlModel {
def fromLocation(location: String): RamlModel = apply(new RamlModelBuilder().buildApi(location))
def fromFile(file: File): RamlModel = apply(new RamlModelBuilder().buildApi(file))
def fromReader(reader: Reader, location: String): RamlModel = apply(new RamlModelBuilder().buildApi(reader, location))
def fromContent(content: Reader, location: String): RamlModel = apply(new RamlModelBuilder().buildApi(content, location))
def apply(parseResult: RamlModelResult): RamlModel = {
if (parseResult.hasErrors)
throw RamlParseError(parseResult.getValidationResults)
new RamlModel(Option(parseResult.getApiV10).getOrElse(throw UnsupportedRamlVersion(s"<1.0")))
}
}
开发者ID:GiGurra,项目名称:raml-gen,代码行数:32,代码来源:RamlModel.scala
示例3:
//设置package包名称以及导入依赖的类
package com.pacbio.common.dependency
import java.io.{Reader, File}
import java.net.URL
import com.typesafe.config.{ConfigParseOptions, ConfigFactory, Config}
trait ConfigProvider {
val parseOptions: Singleton[ConfigParseOptions] = Singleton(ConfigParseOptions.defaults())
val config: Singleton[Config]
}
trait DefaultConfigProvider extends ConfigProvider {
override val config: Singleton[Config] = Singleton(() => ConfigFactory.load(parseOptions()))
}
trait FileConfigProvider extends ConfigProvider {
val configFile: Singleton[File]
override val config: Singleton[Config] =
Singleton(() => ConfigFactory.parseFile(configFile(), parseOptions()))
}
trait ReaderConfigProvider extends ConfigProvider {
val configReader: Singleton[Reader]
override val config: Singleton[Config] =
Singleton(() => ConfigFactory.parseReader(configReader(), parseOptions()))
}
trait URLConfigProvider extends ConfigProvider {
val configURL: Singleton[URL]
override val config: Singleton[Config] =
Singleton(() => ConfigFactory.parseURL(configURL(), parseOptions()))
}
trait StringConfigProvider extends ConfigProvider {
val configString: Singleton[String]
override val config: Singleton[Config] =
Singleton(() => ConfigFactory.parseString(configString(), parseOptions()))
}
开发者ID:PacificBiosciences,项目名称:smrtflow,代码行数:40,代码来源:ConfigProvider.scala
示例4: Pkcs12Convertor
//设置package包名称以及导入依赖的类
package jp.pigumer
import java.io.{OutputStream, Reader}
import java.security.cert.X509Certificate
import java.security.{KeyStore, PrivateKey}
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter
import org.bouncycastle.openssl.{PEMKeyPair, PEMParser}
object Pkcs12Convertor {
def parsePrivateKey(reader: Reader): PrivateKey = {
val pemParser = new PEMParser(reader)
val pemKeyPair = pemParser.readObject().asInstanceOf[PEMKeyPair]
new JcaPEMKeyConverter().getKeyPair(pemKeyPair).getPrivate
}
def parseCertificate(reader: Reader): X509Certificate = {
val pemParser = new PEMParser(reader)
val certificate = pemParser.readObject()
null
}
def write(os: OutputStream, privateKey: PrivateKey, password: Array[Char], certificate: X509Certificate): Unit = {
val keyStore = KeyStore.getInstance("pkcs12")
keyStore.load(null, password)
keyStore.setKeyEntry("1", privateKey, password, Seq(certificate).toArray)
keyStore.store(os, password)
}
}
开发者ID:takesection,项目名称:apple-mdm-certificate,代码行数:33,代码来源:Pkcs12Convertor.scala
示例5: content
//设置package包名称以及导入依赖的类
package com.hypertino.hyperbus.model
import java.io.{Reader, Writer}
import com.hypertino.binders.json.JsonBindersFactory
import com.hypertino.binders.value.{Obj, Value}
import com.hypertino.hyperbus.serialization.{ResponseDeserializer, SerializationOptions}
trait DynamicBody extends Body {
def content: Value
def serialize(writer: Writer)(implicit so: SerializationOptions): Unit = {
import com.hypertino.binders.json.JsonBinders._
import so._
content.writeJson(writer)
}
def copy(
contentType: Option[String] = this.contentType,
content: Value = this.content
): DynamicBody = {
DynamicBody(content, contentType)
}
}
object DynamicBody {
def apply(content: Value, contentType: Option[String]): DynamicBody = DynamicBodyContainer(contentType, content)
def apply(content: Value): DynamicBody = DynamicBodyContainer(None, content)
def apply(reader: Reader, contentType: Option[String]): DynamicBody = {
JsonBindersFactory.findFactory().withReader(reader) { deserializer =>
apply(deserializer.unbind[Value], contentType)
}
}
def unapply(dynamicBody: DynamicBody) = Some((dynamicBody.contentType, dynamicBody.content))
}
private[model] case class DynamicBodyContainer(contentType: Option[String], content: Value) extends DynamicBody
开发者ID:hypertino,项目名称:hyperbus,代码行数:41,代码来源:DynamicBody.scala
示例6: serialize
//设置package包名称以及导入依赖的类
package com.hypertino.hyperbus.model
import java.io.{Reader, Writer}
import com.hypertino.binders.value._
import com.hypertino.hyperbus.serialization.{DeserializeException, SerializationOptions}
trait EmptyBody extends DynamicBody {
override def serialize(writer: Writer)(implicit so: SerializationOptions): Unit = writer.write("{}")
}
case object EmptyBody extends EmptyBody {
def contentType: Option[String] = None
def content = Null
def apply(reader: Reader, contentType: Option[String]): EmptyBody = {
val body = DynamicBody.apply(reader, contentType)
if (body.content.isEmpty)
EmptyBody
else {
throw DeserializeException(s"EmptyBody is expected, but got: '${body.content}'")
}
}
}
开发者ID:hypertino,项目名称:hyperbus,代码行数:24,代码来源:EmptyBody.scala
示例7: DynamicRequest
//设置package包名称以及导入依赖的类
package com.hypertino.hyperbus.model
import java.io.{Reader, Writer}
import com.hypertino.binders.json.JsonBindersFactory
import com.hypertino.binders.value.{Obj, Value}
import com.hypertino.hyperbus.serialization.ResponseDeserializer
import com.hypertino.hyperbus.transport.api.matchers.RequestMatcher
case class DynamicRequest(body: DynamicBody,
headers: RequestHeaders) extends Request[DynamicBody]
case class DynamicRequestObservableMeta(requestMatcher: RequestMatcher)
extends RequestObservableMeta[DynamicRequest]
object DynamicRequest extends RequestMeta[DynamicRequest] {
type ResponseType = DynamicResponse
implicit val requestMeta = this
def apply(hrl: HRL, method: String, body: DynamicBody, headersMap: HeadersMap)
(implicit mcx: MessagingContext): DynamicRequest = {
DynamicRequest(body, RequestHeaders(new HeadersBuilder()
.withHRL(hrl)
.withMethod(method)
.withContentType(body.contentType)
.withContext(mcx)
.++=(headersMap)
.result())
)
}
def apply(hrl: HRL, method: String, body: DynamicBody)
(implicit mcx: MessagingContext): DynamicRequest = {
DynamicRequest(body, RequestHeaders(new HeadersBuilder()
.withHRL(hrl)
.withMethod(method)
.withContentType(body.contentType)
.withContext(mcx)
.result())
)
}
def apply(reader: Reader, headersMap: HeadersMap): DynamicRequest = {
val headers = RequestHeaders(headersMap)
val body = DynamicBody(reader, headers.contentType)
new DynamicRequest(body, headers)
}
override def responseDeserializer: ResponseDeserializer[DynamicResponse] = StandardResponse.dynamicDeserializer
}
开发者ID:hypertino,项目名称:hyperbus,代码行数:51,代码来源:DynamicRequest.scala
示例8: MessageReader
//设置package包名称以及导入依赖的类
package com.hypertino.hyperbus.serialization
import java.io.{Reader, StringReader}
import com.fasterxml.jackson.core.{JsonFactory, JsonParser}
import com.hypertino.binders.json.{JacksonParserAdapter, JsonBindersFactory}
import com.hypertino.binders.value.{Obj, Text, Value}
import com.hypertino.hyperbus.model.{Body, Header, Headers, HeadersMap, Message}
object MessageReader {
def read[M <: Message[_ <: Body,_ <: Headers]](reader: Reader, concreteDeserializer: MessageDeserializer[M]): M = {
val jacksonFactory = new JsonFactory()
jacksonFactory.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE)
val jp = jacksonFactory.createParser(reader)
val headers = try {
val adapter = new JacksonParserAdapter(jp)
val headers = JsonBindersFactory.findFactory().withJsonParserApi(adapter) { jpa ?
val headersSeq = jpa.unbind[Value].asInstanceOf[Obj].v.toSeq // todo: this isn't great, also see https://github.com/hypertino/binders/issues/2
val transformedSeq = headersSeq.map {
case (Header.CONTENT_TYPE, value) ? Header.CONTENT_TYPE ? JsonContentTypeConverter.universalJsonContentTypeToSimple(value)
case other ? other
}
HeadersMap(transformedSeq: _*)
}
jp.nextToken()
val offset = jp.getTokenLocation.getCharOffset
reader.reset()
reader.skip(offset)
headers
}
finally {
jp.close()
}
concreteDeserializer(reader, headers)
}
def fromString[M <: Message[_ <: Body,_ <: Headers]](message: String, concreteDeserializer: MessageDeserializer[M]): M = {
val stringReader = new StringReader(message)
try {
read(stringReader, concreteDeserializer)
}
finally {
stringReader.close()
}
}
}
开发者ID:hypertino,项目名称:hyperbus,代码行数:52,代码来源:MessageReader.scala
示例9: ArtifactSourceBackedMustacheResolver
//设置package包名称以及导入依赖的类
package com.atomist.project.common.template
import java.io.{Reader, StringReader}
import com.atomist.source.ArtifactSource
import com.github.mustachejava.resolver.DefaultResolver
import com.typesafe.scalalogging.LazyLogging
class ArtifactSourceBackedMustacheResolver(artifactSource: ArtifactSource)
extends DefaultResolver
with LazyLogging{
override def getReader(resourceName: String): Reader = {
logger.debug(s"Need to return Reader for $resourceName")
artifactSource.findFile(resourceName) match {
case Some(f) => new StringReader(f.content)
case _ => new StringReader(resourceName)
}
}
}
开发者ID:atomist,项目名称:rug,代码行数:21,代码来源:ArtifactSourceBackedMustacheResolver.scala
示例10: MonitoredIOReader
//设置package包名称以及导入依赖的类
package faunadb.importer.lang
import java.io.Reader
object MonitoredIOReader {
type Callback = (Long) => Unit
def apply(delegate: Reader)(fn: Callback): MonitoredIOReader =
new MonitoredIOReader(fn, delegate)
}
final class MonitoredIOReader private(callback: MonitoredIOReader.Callback, delegate: Reader) extends Reader {
def read(cbuf: Array[Char], off: Int, len: Int): Int = {
val bytesRead = delegate.read(cbuf, off, len)
if (bytesRead != -1) callback(bytesRead)
bytesRead
}
def close(): Unit = delegate.close()
}
开发者ID:fauna,项目名称:faunadb-importer,代码行数:21,代码来源:MonitoredIOReader.scala
示例11: SortCodeSubstitutionTable
//设置package包名称以及导入依赖的类
package com.github.mpetruska.ukmodulo.table
import java.io.Reader
import com.github.mpetruska.ukmodulo.Error
import com.github.mpetruska.ukmodulo.digits.AccountDigits
import com.github.mpetruska.ukmodulo.table.SortCodeSubstitutionRowParser._
object SortCodeSubstitutionTable extends ResourceTable {
type Row = SortCodeSubstitutionRow
val resourcePath = "/scsubtab.txt"
def parseAllRows(in: Reader): Either[Error, List[Row]] = {
SortCodeSubstitutionRowParser.parseAllRows(in) match {
case Success(value, _) => Right(value)
case NoSuccess(error, _) => Left(error)
}
}
def performSubstitutionFor(accountDigits: AccountDigits): Either[Error, AccountDigits] = {
table.right.flatMap { substitutionTable =>
val originalSortCode = AccountDigits.getSortCode(accountDigits)
substitutionTable.find(_.originalSortCode == originalSortCode) match {
case None => Right(accountDigits)
case Some(substitute) => AccountDigits.parse(substitute.substitution, AccountDigits.getAccountNumber(accountDigits))
}
}
}
}
开发者ID:mpetruska,项目名称:uk-modulo-scala,代码行数:33,代码来源:SortCodeSubstitutionTable.scala
示例12: ModulusWeightTable
//设置package包名称以及导入依赖的类
package com.github.mpetruska.ukmodulo.table
import java.io.Reader
import com.github.mpetruska.ukmodulo.Error
import com.github.mpetruska.ukmodulo.digits.AccountDigits
import com.github.mpetruska.ukmodulo.table.ModulusWeightRowParser._
object ModulusWeightTable extends ResourceTable {
type Row = ModulusWeightRow
val resourcePath = "/valacdosv440.txt"
def parseAllRows(in: Reader): Either[Error, List[Row]] = {
ModulusWeightRowParser.parseAllRows(in) match {
case Success(value, _) => Right(value)
case NoSuccess(error, _) => Left(error)
}
}
def getWeightRowsFor(accountDigits: AccountDigits): Either[Error, List[ModulusWeightRow]] = {
val accountNumber = AccountDigits.getSortCode(accountDigits)
table.right.map { weightTable =>
weightTable.filter(row => row.rangeStart <= accountNumber && row.rangeEnd >= accountNumber)
}
}
}
开发者ID:mpetruska,项目名称:uk-modulo-scala,代码行数:30,代码来源:ModulusWeightTable.scala
示例13: Starscream
//设置package包名称以及导入依赖的类
package com.iofficecorp.svg
import java.io.Reader
import java.io.Writer
import org.xml.sax.{XMLReader, Attributes, InputSource}
import org.xml.sax.helpers.XMLReaderFactory
import org.dom4j.io.XMLWriter
object Starscream {
private implicit class FilterChain(val reader: XMLReader) {
def chain(newReader: XMLReader => XMLReader): FilterChain =
new FilterChain(newReader(reader))
}
def transformSVGFromReaderToWriter(
reader: Reader,
writer: Writer,
scale:Float = 1.0f,
minimum:Float = Float.MinValue)
: Unit = {
val filter =
XMLReaderFactory.createXMLReader()
.chain(new ScaleFilter(_, scale))
.chain(new MinimumFilter(_, minimum))
.chain(new StripWhitespaceFilter(_, "id"))
.chain(new StripWhitespaceFilter(_, "href"))
.reader
val xmlWriter = new XMLWriter(writer)
filter.setContentHandler(xmlWriter)
filter.parse(new InputSource(reader))
}
}
开发者ID:iOffice,项目名称:starscream,代码行数:36,代码来源:Starscream.scala
示例14: withStringParser
//设置package包名称以及导入依赖的类
package com.hypertino.binders.json
import java.io.{Reader, Writer}
import com.hypertino.binders.core.{BindOptions, Deserializer, Serializer}
import com.hypertino.binders.json.api.{JsonBindersFactoryApi, JsonGeneratorApi, JsonParserApi}
import com.hypertino.inflector.naming.{Converter, PlainConverter}
import scala.scalajs.js
import scala.scalajs.js.JSON
trait JsonBindersFactory[C <: Converter, S <: Serializer[C], D <: Deserializer[C]]
extends JsonBindersFactoryApi[C, S, D] {
override def withStringParser[T](jsonString: String)
(codeBlock: D ? T)
(implicit bindOptions: BindOptions): T = {
val adapter = new JsParserAdapter(JSON.parse(jsonString))
val jds = createDeserializer(adapter)
codeBlock(jds)
}
override def withReader[T](reader: Reader)
(codeBlock: (D) ? T)
(implicit bindOptions: BindOptions): T = {
val stringBuilder = new StringBuilder
val len = 256
val buffer = new Array[Char](len)
var readed = len
while (readed == len) {
readed = reader.read(buffer, 0, len)
stringBuilder.append(buffer, 0, readed)
}
withStringParser(stringBuilder.toString())(codeBlock)
}
def withJsonObjectParser[T](jsonObject: js.Dynamic)
(codeBlock: D ? T)
(implicit bindOptions: BindOptions): T = {
withJsonParserApi(new JsParserAdapter(jsonObject))(codeBlock)
}
override def withWriter(writer: Writer)
(codeBlock: S ? Unit)
(implicit bindOptions: BindOptions): Unit = {
withJsonGeneratorApi(new JsGeneratorAdapter(writer))(codeBlock)
}
}
object JsonBindersFactory {
implicit val defaultJsonBindersFactory = new DefaultJsonBindersFactory[PlainConverter.type]
def findFactory[C <: Converter, S <: Serializer[C], D <: Deserializer[C]]()
(implicit factory: JsonBindersFactory[C, S, D]): JsonBindersFactory[C, S, D] = factory
}
开发者ID:hypertino,项目名称:json-binders,代码行数:55,代码来源:JsonBindersFactory.scala
示例15: createSerializer
//设置package包名称以及导入依赖的类
package com.hypertino.binders.json.api
import java.io.{Reader, StringReader, StringWriter, Writer}
import com.hypertino.binders.core.{BindOptions, Deserializer, Serializer}
import com.hypertino.inflector.naming.Converter
trait JsonBindersFactoryApi[C <: Converter, S <: Serializer[C], D <: Deserializer[C]] {
def createSerializer(jsonGenerator: JsonGeneratorApi)(implicit bindOptions: BindOptions): S
def createDeserializer(jsonParser: JsonParserApi)(implicit bindOptions: BindOptions): D
def prettyPrint: Boolean = false
def withStringParser[T](jsonString: String)(codeBlock: D ? T)(implicit bindOptions: BindOptions): T = {
val reader = new StringReader(jsonString)
try {
withReader[T](reader)(codeBlock)
} finally {
reader.close()
}
}
def withStringGenerator(codeBlock: S ? Unit)(implicit bindOptions: BindOptions): String = {
val writer = new StringWriter()
try {
withWriter(writer)(codeBlock)
} finally {
writer.close()
}
writer.toString
}
def withJsonParserApi[T](jsonParserApi: JsonParserApi)(codeBlock: D ? T)(implicit bindOptions: BindOptions): T = {
val jds = createDeserializer(jsonParserApi)
codeBlock(jds)
}
def withJsonGeneratorApi(jsonGeneratorApi: JsonGeneratorApi)(codeBlock: S ? Unit)(implicit bindOptions: BindOptions): Unit = {
val js = createSerializer(jsonGeneratorApi)
codeBlock(js)
}
def withReader[T](reader: Reader)(codeBlock: D ? T)(implicit bindOptions: BindOptions): T
def withWriter(writer: Writer)(codeBlock: S ? Unit)(implicit bindOptions: BindOptions): Unit
}
开发者ID:hypertino,项目名称:json-binders,代码行数:46,代码来源:JsonBindersFactoryApi.scala
示例16: JsonBinders
//设置package包名称以及导入依赖的类
package com.hypertino.binders.json
import java.io.{InputStream, Reader, Writer}
import com.hypertino.binders.json.internal.JsonMacro
import scala.language.experimental.macros
object JsonBinders {
implicit class JsonStringReader(val reader: Reader) extends AnyVal {
def readJson[O]: O = macro JsonMacro.readJson[O]
}
implicit class JsonStringWriter[O](val obj: O) extends AnyVal {
def writeJson(writer: Writer): Unit = macro JsonMacro.writeJson[O]
}
implicit class JsonStringParser(val jsonString: String) extends AnyVal {
def parseJson[O]: O = macro JsonMacro.parseJson[O]
}
implicit class JsonStringGenerator[O](val obj: O) extends AnyVal {
def toJson: String = macro JsonMacro.toJson[O]
}
}
开发者ID:hypertino,项目名称:json-binders,代码行数:26,代码来源:JsonBinders.scala
注:本文中的java.io.Reader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论