有什么问题GZIPInputStream或GZIPOutputStream.请阅读以下代码(或运行它,看看会发生什么):
def main(a: Array[String]) {
val name = "test.dat"
new GZIPOutputStream(new FileOutputStream(name)).write(10)
println(new GZIPInputStream(new FileInputStream(name)).read())
}
Run Code Online (Sandbox Code Playgroud)
它创建一个文件test.dat,10通过GZIP 写入单字节格式,并以相同的格式读取同一文件中的字节.
这就是我运行它的原因:
Exception in thread "main" java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(Unknown Source)
at java.util.zip.InflaterInputStream.read(Unknown Source)
at java.util.zip.GZIPInputStream.read(Unknown Source)
at java.util.zip.InflaterInputStream.read(Unknown Source)
at nbt.Test$.main(Test.scala:13)
at nbt.Test.main(Test.scala)
Run Code Online (Sandbox Code Playgroud)
由于某种原因,阅读线似乎走错了路.
我搜索了该错误,Unexpected end of ZLIB input stream并发现了一些针对Oracle的错误报告,这些报告是在2007-2010左右发布的.所以我猜这个bug仍然存在,但我不确定我的代码是否正确,所以让我在这里发帖并听取你的意见.谢谢!
在反应香蕉,我试图运行reactimate :: Event (IO ()) -> Moment ()与一些动作Arduino在hArduino包,的一个实例MonadIO.Arduino a -> IO a包中似乎没有提供任何功能.你将如何执行Arduino行动reactimate?
我正在尝试使用ReplayKit录制我的应用程序屏幕,在录制视频时裁剪掉它的某些部分.不太顺利.
ReplayKit将捕获整个屏幕,因此我决定从ReplayKit接收每个帧(作为CMSampleBuffervia startCaptureWithHandler),在那里裁剪并通过AVAssetWriterInputPixelBufferAdaptor将其提供给视频编写器.但是我在修剪图像缓冲区之前遇到了麻烦.
这是我记录整个屏幕的工作代码:
// Starts recording with a completion/error handler
-(void)startRecordingWithHandler: (RPHandler)handler
{
// Sets up AVAssetWriter that will generate a video file from the recording.
self.writer = [AVAssetWriter assetWriterWithURL:self.outputFileURL
fileType:AVFileTypeQuickTimeMovie
error:nil];
NSDictionary* outputSettings =
@{
AVVideoWidthKey : @(screen.size.width), // The whole width of the entire screen.
AVVideoHeightKey : @(screen.size.height), // The whole height of the entire screen.
AVVideoCodecKey : AVVideoCodecTypeH264,
};
// Sets up AVAssetWriterInput that will feed ReplayKit's …Run Code Online (Sandbox Code Playgroud) 我需要一个ActorSystem不记录任何内容的东西.用喷雾尝试HTTP的东西,我是如此愚蠢,以至于我无法在这里复制和粘贴他们的示例代码.正如你会看到他们正在使用的ActorSystem,其默认配置会使用一大堆INFO来混淆stdout.那你怎么做一个ActorSystem符合我需要的呢?如果可以在没有任何外部XML或配置文件的情况下完成,我会喜欢这种方式.谢谢!:)
我想一个函数,在一个列表Maybe a,并返回Just [a]如果所有的内容Just a,否则返回Nothing.
f :: [Maybe a] -> Maybe [a]
-- f [Just x, Just y ] = Just [x, y]
-- f [Just x, Nothing] = Nothing
Run Code Online (Sandbox Code Playgroud)
我认为它不一定是Maybe,List但任何Functor Applicative或者Monad,但我想不起来.
我想将一个可变映射转换为封闭范围内的不可变映射.以下是情况和无意义防御副本的示例代码:
def func(): immutable.Map[String, Int] = {
val map = mutable.HashMap[String, Int]
// here goes operations for the map
return immutable.HashMap ++ map
}
Run Code Online (Sandbox Code Playgroud)
当我写"无意义"时,在这里做防御性复制完全是浪费,因为可变地图实际上是从外部不可变的.如果我们只能从外部看到getter操作,那么性能应该更好.
问题是我真的不知道该怎么做.我试过用匿名的不可变映射实例简单地包装它,但是这个方法def +[B1 >: B](kv: (A, B1))使它变得不可能.
请帮我!
编辑:刚才忘了修复返回类型[Int, Int]来[String, Int]
通过n-depth structure我的意思是一些结构嵌套一种结构化的n时间,例如[[a]]是2纵深列表.
我正在随机思考一个实例Functor,Foldable以及今天Traversable的3个深度列表([[[a]]]),并且发现了一些规律性,如下所示:
instance Functor [[[]]] where
fmap f n = fmap (fmap (fmap f)) n
instance Foldable [[[]]] where
foldMap f n = foldMap (foldMap (foldMap f)) n
instance Traversable [[[]]] where
sequenceA n =
let fz = \z -> sequenceA z
fy = \y -> sequenceA (fmap fz y)
fx = \x -> sequenceA (fmap fy x)
in fx n
Run Code Online (Sandbox Code Playgroud)
我认为这可以通过某种方式安全地自动化,不仅适用于[]具有这些实例的任何结构(如Vector …
我的项目中有一个令人困惑的问题并且无法解决它,所以请帮助我!
这是一个简化原始代码的示例代码:
trait Sample[A] {
def doit(param: A)
}
case object SampleEx1 extends Sample[Int] {
def doit(param: Int) = {
param + 0
}
}
Run Code Online (Sandbox Code Playgroud)
现在我需要根据A外部原因进行协方差,但是如果注释掉它会导致错误:
trait Sample[+A] {
def doit(param: A) // ERR: covariant type A occurs in contravariant position in type A of value param
}
case object SampleEx1 extends Sample[Int] {
def doit(param: Int) = {
param + 0
}
}
Run Code Online (Sandbox Code Playgroud)
所以我stacoverflow并找到另一种类型的解决方案B,但然后发生另一个错误:
trait Sample[+A] {
def doit[B >: A](param: B)
} …Run Code Online (Sandbox Code Playgroud) 我有一个类型Foo a,想要一个EnumFoo a需要的类型instance Enum (Foo a).你怎么声明这种类型?
假设我们这样声明Foo:
type Foo a = Maybe a
Run Code Online (Sandbox Code Playgroud)
可以有Foo Int,有Foo String什么.
现在我声明一个Enumon 的实例Foo Int:
instance Enum (Foo Int) where
...
Run Code Online (Sandbox Code Playgroud)
可能还有其他Foo一些具有这样的实例Enum.我们称之为那些类型EnumFoo a.你是怎么表达的?
这不起作用,但我想做的是:
type (Enum (Foo a)) => EnumFoo a = Foo a
Run Code Online (Sandbox Code Playgroud)
我不确定它叫什么,所以标题应该毫无意义.
是否有算法引导给定数量的三值逻辑值的所有可能组合?
例如,F(2)应该返回此列表:
t t
t u
t f
u t
u u
u f
f t
f u
f f
Run Code Online (Sandbox Code Playgroud)
该函数看起来像这样(在Haskell中):
data Tril = FALSE | NULL | TRUE
all :: Int -> [[Tril]]
all amount = ???
all1 :: [Tril]
all1 = join (all 1)
all2 :: [(Tril, Tril)]
all2 = map (\[f, s] -> (f, s)) (all 2)
all3 :: [(Tril, Tril, Tril)]
all3 = map (\[f, s, t] -> (f, s, t)) (all 3)
Run Code Online (Sandbox Code Playgroud) haskell ×5
scala ×4
akka ×1
covariance ×1
frp ×1
immutability ×1
io ×1
ios ×1
ios11 ×1
java ×1
logging ×1
map ×1
mutable ×1
objective-c ×1
replaykit ×1