本文整理汇总了Scala中java.io.DataInputStream类的典型用法代码示例。如果您正苦于以下问题:Scala DataInputStream类的具体用法?Scala DataInputStream怎么用?Scala DataInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataInputStream类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: FrameUtils
//设置package包名称以及导入依赖的类
package com.softwaremill.modemconnector
import java.io.{DataInputStream, File, FileInputStream}
import com.softwaremill.modemconnector.agwpe.AGWPEFrame
import com.softwaremill.modemconnector.ax25.AX25Frame
object FrameUtils {
def ax25frameFromFile(filePath: String): AX25Frame = {
val file: File = new File(this.getClass.getResource(filePath).getPath)
AX25Frame(AGWPEFrame(new DataInputStream(new FileInputStream(file))).data.get)
}
def dataStream(filePath: String): DataInputStream = {
val file: File = new File(this.getClass.getResource(filePath).getPath)
new DataInputStream(new FileInputStream(file))
}
}
开发者ID:softwaremill,项目名称:modem-connector,代码行数:20,代码来源:FrameUtils.scala
示例2: WritableSerializer
//设置package包名称以及导入依赖的类
package org.hammerlab.hadoop.kryo
import java.io.{ DataInputStream, DataOutputStream }
import com.esotericsoftware.kryo.io.{ Input, Output }
import com.esotericsoftware.kryo.{ Kryo, Serializer }
import org.apache.hadoop.io.Writable
class WritableSerializer[T <: Writable](ctorArgs: Any*) extends Serializer[T] {
override def read(kryo: Kryo, input: Input, clz: Class[T]): T = {
val t = clz.newInstance()
t.readFields(new DataInputStream(input))
t
}
override def write(kryo: Kryo, output: Output, t: T): Unit = {
t.write(new DataOutputStream(output))
}
}
开发者ID:hammerlab,项目名称:spark-util,代码行数:20,代码来源:WritableSerializer.scala
示例3: AvroUtils
//设置package包名称以及导入依赖的类
package pulse.kafka.avro
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, File}
import com.twitter.util.Future
import org.apache.avro.Schema
import org.apache.avro.file.DataFileWriter
import org.apache.avro.generic.{GenericDatumReader, GenericDatumWriter, GenericRecord}
import org.apache.avro.io.DecoderFactory
import pulse.kafka.extensions.managedByteArrayInputStream
import pulse.kafka.extensions.managedByteArrayOutputStream
import pulse.kafka.extensions.catsStdInstancesForFuture
import scala.concurrent.ExecutionContext.Implicits._
object AvroUtils {
import pulse.common.syntax._
def jsonToAvroBytes(json: String, schemaFile: File): Future[Array[Byte]] =
use(new ByteArrayOutputStream()) { output =>
for {
s <- loadSchema(schemaFile)
_ <- convertImpl(json, output, s)
} yield output.toByteArray
}
private def convertImpl(json: String, output: ByteArrayOutputStream, schemaSpec: Schema): Future[GenericDatumReader[GenericRecord]] =
use(new ByteArrayInputStream(json.getBytes)) { input =>
for {
w <- getWriter(output, schemaSpec)
r <- getReader(input, schemaSpec, w)
} yield r
}
def getReader(input: ByteArrayInputStream, schemaSpec: Schema, w: DataFileWriter[GenericRecord]) = Future.value {
val reader = new GenericDatumReader[GenericRecord](schemaSpec)
val datum = reader.read(null, getJsonDecoder(input, schemaSpec))
w.append(datum)
w.flush()
reader
}
private def getJsonDecoder(input: ByteArrayInputStream, schema: Schema) =
DecoderFactory.get.jsonDecoder(schema, new DataInputStream(input))
private def getWriter(output: ByteArrayOutputStream, schemaSpec: Schema) = {
Future.value {
val writer = new DataFileWriter[GenericRecord](new GenericDatumWriter[GenericRecord]())
writer.create(schemaSpec, output)
}
}
private def loadSchema(schemaFile: File): Future[Schema] =
Future {
new Schema.Parser().parse(schemaFile)
}
}
开发者ID:gpulse,项目名称:kafka,代码行数:60,代码来源:AvroUtils.scala
示例4: ReadRectangles
//设置package包名称以及导入依赖的类
package scala.test
import java.io.IOException
import java.io.DataInputStream
import java.io.FileInputStream
import core.scala.RectangleTuple
object ReadRectangles {
def readDoublePointRecs(dimension : Int, dis : DataInputStream) : Stream[RectangleTuple] = {
val leftP = new Array[Double](dimension)
val rightP = new Array[Double](dimension)
for (i <- 0 until dimension){
leftP(i) = dis.readDouble()
}
for (i <- 0 until dimension){
rightP(i) = dis.readDouble()
}
new RectangleTuple(leftP, rightP) #:: readDoublePointRecs(dimension, dis)
}
def main(args: Array[String]){
val dis = new DataInputStream(new FileInputStream("/home/da/data/rea02.rec"))
try{
readDoublePointRecs(2, dis).take(10).foreach { x => println(x) }
}catch {
case e : IOException => e.printStackTrace();
}finally {
dis.close()
}
}
}
开发者ID:daniarleagk,项目名称:rbulkloading,代码行数:36,代码来源:ReadRectangles.scala
示例5: AvroUtils
//设置package包名称以及导入依赖的类
package pulse.services.example.avro
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, File}
import org.apache.avro.Schema
import org.apache.avro.file.DataFileWriter
import org.apache.avro.generic.{GenericDatumReader, GenericDatumWriter, GenericRecord}
import org.apache.avro.io.DecoderFactory
import pulse.services.example.extensions._
object AvroUtils {
def jsonToAvroBytes(json: String, schemaFile: File) = {
use(new ByteArrayOutputStream())(output => {
val schemaSpec = loadSchema(schemaFile)
use(new ByteArrayInputStream(json.getBytes))(input => {
val writer = new DataFileWriter[GenericRecord](new GenericDatumWriter[GenericRecord]())
writer.create(schemaSpec, output)
val reader = new GenericDatumReader[GenericRecord](schemaSpec)
val datum = reader.read(null, getJsonDecoder(input, schemaSpec))
writer.append(datum)
writer.flush()
})
output.toByteArray
})
}
def getJsonDecoder(input: ByteArrayInputStream, schema: Schema) =
DecoderFactory.get.jsonDecoder(schema, new DataInputStream(input))
def loadSchema(schemaFile: File) =
new Schema.Parser().parse(schemaFile)
}
开发者ID:gpulse,项目名称:services,代码行数:34,代码来源:AvroUtils.scala
示例6: WeatherRequested
//设置package包名称以及导入依赖的类
package zeroweather.message
case class WeatherRequested(countryCode: String, city: String)
object WeatherRequested {
//TODO: Replace with case class codecs once the new release of msgpack4s is published
import java.io.{ DataInputStream, DataOutputStream }
import org.velvia.msgpack.RawStringCodecs._
import org.velvia.msgpack._
implicit object WeatherRequestedMsgPackCodec extends Codec[WeatherRequested] {
def pack(out: DataOutputStream, item: WeatherRequested) = {
out.write(0x01 | Format.MP_FIXARRAY)
StringCodec.pack(out, item.countryCode)
StringCodec.pack(out, item.city)
}
val unpackFuncMap: FastByteMap[WeatherRequestedMsgPackCodec.UnpackFunc] = FastByteMap[UnpackFunc](
(0x01 | Format.MP_FIXARRAY).toByte -> { in: DataInputStream =>
val countryCode = StringCodec.unpack(in)
val city = StringCodec.unpack(in)
WeatherRequested(countryCode, city)
}
)
}
}
开发者ID:sbilinski,项目名称:zeroweather,代码行数:29,代码来源:WeatherRequested.scala
示例7: Weather
//设置package包名称以及导入依赖的类
package zeroweather.message
case class Weather(timestamp: Long, countryCode: String, city: String, temperatureInCelsius: BigDecimal)
object Weather {
//TODO: Replace with case class codecs once the new release of msgpack4s is published
import java.io.{ DataInputStream, DataOutputStream }
import org.velvia.msgpack.RawStringCodecs._
import org.velvia.msgpack.SimpleCodecs._
import org.velvia.msgpack._
implicit object WeatherMsgPackCodec extends Codec[zeroweather.message.Weather] {
def pack(out: DataOutputStream, item: Weather) = {
out.write(0x01 | Format.MP_FIXARRAY)
LongCodec.pack(out, item.timestamp)
StringCodec.pack(out, item.countryCode)
StringCodec.pack(out, item.city)
StringCodec.pack(out, item.temperatureInCelsius.toString)
}
val unpackFuncMap: FastByteMap[WeatherMsgPackCodec.UnpackFunc] = FastByteMap[UnpackFunc](
(0x01 | Format.MP_FIXARRAY).toByte -> { in: DataInputStream =>
val timestamp = LongCodec.unpack(in)
val countryCode = StringCodec.unpack(in)
val city = StringCodec.unpack(in)
val celsius = BigDecimal(StringCodec.unpack(in))
Weather(timestamp, countryCode, city, celsius)
}
)
}
}
开发者ID:sbilinski,项目名称:zeroweather,代码行数:34,代码来源:Weather.scala
示例8: TransactionGenerator
//设置package包名称以及导入依赖的类
package com.bwsw.sj.transaction.generator.server
import java.io.{DataInputStream, DataOutputStream}
import java.net.Socket
import java.util.concurrent.atomic.{AtomicBoolean, AtomicInteger, AtomicLong}
import com.bwsw.sj.common.utils.TransactionGeneratorLiterals
class TransactionGenerator(socket: Socket, doesServerWork: AtomicBoolean) extends Runnable {
private val counter = new AtomicInteger(0)
private val currentMillis = new AtomicLong(0)
private val inputStream = new DataInputStream(socket.getInputStream)
private val outputStream = new DataOutputStream(socket.getOutputStream)
private val scale = TransactionGeneratorLiterals.scale
override def run(): Unit = {
try {
while (doesServerWork.get()) {
if (isClientAvailable) {
val id = generateID()
send(id)
} else {
close()
return
}
}
} catch {
case ex: Exception =>
close()
}
}
private def isClientAvailable = {
val clientRequestStatus = inputStream.read()
clientRequestStatus != -1
}
private def generateID() = this.synchronized {
val now = System.currentTimeMillis()
if (now - currentMillis.get > 0) {
currentMillis.set(now)
counter.set(0)
}
now * scale + counter.getAndIncrement()
}
private def send(id: Long) {
outputStream.writeLong(id)
}
private def close() = {
inputStream.close()
outputStream.close()
socket.close()
}
}
开发者ID:bwsw,项目名称:sj-platform,代码行数:58,代码来源:TransactionGenerator.scala
示例9: TempFileTest
//设置package包名称以及导入依赖的类
package com.twitter.io
import java.io.{ByteArrayInputStream, DataInputStream}
import java.util.Arrays
import org.junit.runner.RunWith
import org.scalatest.WordSpec
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class TempFileTest extends WordSpec {
"TempFile" should {
"load resources" in {
val f1 = TempFile.fromResourcePath("/java/lang/String.class")
val f2 = TempFile.fromResourcePath(getClass, "/java/lang/String.class")
val f3 = TempFile.fromSystemResourcePath("java/lang/String.class")
val c1 = Files.readBytes(f1)
val c2 = Files.readBytes(f2)
val c3 = Files.readBytes(f3)
assert(Arrays.equals(c1, c2))
assert(Arrays.equals(c2, c3))
assert(new DataInputStream(new ByteArrayInputStream(c1)).readInt == 0xcafebabe)
}
}
}
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:32,代码来源:TempFileTest.scala
示例10: AMQContentHeader
//设置package包名称以及导入依赖的类
package chana.mq.amqp.model
import chana.mq.amqp.method.UnknownClassOrMethodId
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.DataInputStream
import java.io.DataOutputStream
import java.io.IOException
object AMQContentHeader {
def readFrom(payload: Array[Byte]): BasicProperties = {
val in = new DataInputStream(new ByteArrayInputStream(payload))
readFrom(in)
}
@throws(classOf[IOException])
def readFrom(in: DataInputStream): BasicProperties = {
in.readShort() match {
case 60 => BasicProperties.readFrom(in)
case classId => throw new UnknownClassOrMethodId(classId)
}
}
}
abstract class AMQContentHeader extends Cloneable {
def weight: Short = 0
def bodySize: Long
@throws(classOf[IOException])
def writeTo(out: DataOutputStream, bodySize: Long) {
out.writeShort(weight)
out.writeLong(bodySize)
writePropertiesTo(new ContentHeaderPropertyWriter(new ValueWriter(out)))
}
@throws(classOf[IOException])
def writePropertiesTo(writer: ContentHeaderPropertyWriter)
@throws(classOf[IOException])
def toFrame(channelNumber: Int, bodySize: Long): Frame = {
val out = new ByteArrayOutputStream()
val os = new DataOutputStream(out)
os.writeShort(classId)
writeTo(os, bodySize)
os.flush()
Frame(Frame.HEADER, channelNumber, out.toByteArray)
}
@throws(classOf[CloneNotSupportedException])
override def clone(): AnyRef = super.clone()
}
开发者ID:qingmang-team,项目名称:chanamq,代码行数:54,代码来源:AMQContentHeader.scala
示例11: Access
//设置package包名称以及导入依赖的类
package chana.mq.amqp.method
import chana.mq.amqp.model.ValueReader
import java.io.DataInputStream
import java.io.IOException
object Access extends AMQClass {
val id = 30
val name = "access"
@throws(classOf[IOException])
def readFrom(in: DataInputStream): Method = {
val rdr = new ArgumentsReader(new ValueReader(in))
in.readShort() match {
case 10 => Request(rdr.readShortstr(), rdr.readBit(), rdr.readBit(), rdr.readBit(), rdr.readBit(), rdr.readBit())
case 11 => RequestOk(rdr.readShort())
case mId => throw new UnknownClassOrMethodId(id, mId)
}
}
final case class Request(realm: String, exclusive: Boolean, passive: Boolean, active: Boolean, write: Boolean, read: Boolean) extends Method(10, "request") {
assert(realm != null, nonNull("realm"))
def hasContent = false
def expectResponse = true
@throws(classOf[IOException])
def writeArgumentsTo(writer: ArgumentsWriter) {
writer.writeShortstr(this.realm)
writer.writeBit(this.exclusive)
writer.writeBit(this.passive)
writer.writeBit(this.active)
writer.writeBit(this.write)
writer.writeBit(this.read)
}
}
final case class RequestOk(reserved_1: Int) extends Method(11, "request-ok") {
def hasContent = false
def expectResponse = false
@throws(classOf[IOException])
def writeArgumentsTo(writer: ArgumentsWriter) {
writer.writeShort(this.reserved_1)
}
}
}
开发者ID:qingmang-team,项目名称:chanamq,代码行数:50,代码来源:Access.scala
示例12: Confirm
//设置package包名称以及导入依赖的类
package chana.mq.amqp.method
import chana.mq.amqp.model.ValueReader
import java.io.DataInputStream
import java.io.IOException
object Confirm extends AMQClass {
val id = 85
val name = "confirm"
@throws(classOf[IOException])
def readFrom(in: DataInputStream): Method = {
val rdr = new ArgumentsReader(new ValueReader(in))
in.readShort() match {
case 10 => Select(rdr.readBit())
case 11 => SelectOk
case mId => throw new UnknownClassOrMethodId(id, mId)
}
}
final case class Select(nowait: Boolean) extends Method(10, "select") {
def hasContent = false
def expectResponse = true
@throws(classOf[IOException])
def writeArgumentsTo(writer: ArgumentsWriter) {
writer.writeBit(this.nowait)
}
}
case object SelectOk extends Method(11, "select-ok") {
def hasContent = false
def expectResponse = false
@throws(classOf[IOException])
def writeArgumentsTo(writer: ArgumentsWriter) {
}
}
}
开发者ID:qingmang-team,项目名称:chanamq,代码行数:43,代码来源:Confirm.scala
注:本文中的java.io.DataInputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论