小编Sri*_*vas的帖子

Scala,将多个列表转换为元组列表

我有3个列表

val a = List("a", "b", "c")
val b = List(1, 2, 3)
val c = List(4, 5, 6)
Run Code Online (Sandbox Code Playgroud)

我想将它们转换如下

List(("a", 1, 4), ("b", 2, 5), ("c", 3, 6))
Run Code Online (Sandbox Code Playgroud)

请告诉我如何获得此结果

scala

5
推荐指数
3
解决办法
5392
查看次数

嵌入式码头实现 HttpSessionListener

我正在尝试使用带有代理servlet的嵌入式jetty实现HttpSessionListener接口,我已经注册了SessionListener,但它根本没有被调用,这里是代码,

   public class JettyProxy {

    public static void main(String[] args) throws Exception {
        Server server = new Server();
        CustomProxyServlet customProxyServlet = new CustomProxyServlet();


        ServerConnector connector = new ServerConnector(server);
        connector.setPort(8888);
        server.addConnector(connector);

        ConnectHandler proxy = new ConnectHandler();

        server.setHandler(proxy);

        ServletContextHandler context = new ServletContextHandler(proxy, "/",
                ServletContextHandler.SESSIONS);
        ServletHolder proxyServlet = new ServletHolder(customProxyServlet);

        context.addServlet(proxyServlet, "/*");

        if (context.getSessionHandler() == null) {
            System.out.println("Session handler is null");
        } else {
            System.out.println("Session handler is not null");
        }

        if (context.getSessionHandler().getSessionManager() == null) {
            System.out.println("Managaer it null");
        } else {
            System.out.println("Manager …
Run Code Online (Sandbox Code Playgroud)

jetty embedded-jetty

5
推荐指数
1
解决办法
2875
查看次数

使用scala下载图像文件

我正在尝试下载Latex公式的图像文件.以下是我正在使用的代码

    var out: OutputStream = null;
    var in: InputStream = null;

    try {
      val url = new URL("http://latex.codecogs.com/png.download?$$I=\frac{dQ}{dt}$$")

      val connection = url.openConnection().asInstanceOf[HttpURLConnection]
      connection.setRequestMethod("GET")
      in = connection.getInputStream
      val localfile = "sample2.png"
      out = new BufferedOutputStream(new FileOutputStream(localfile))
      val byteArray = Stream.continually(in.read).takeWhile(-1 !=).map(_.toByte).toArray

      out.write(byteArray)
    } catch {
      case e: Exception => println(e.printStackTrace()) 
    } finally {
      out.close
      in.close
    }
Run Code Online (Sandbox Code Playgroud)

我可以下载,但它没有下载完整的图像,预期的图像大小约为517字节,但它只下载275字节.它可能出了什么问题.附上不完整和完整的图像.请帮我.我使用相同的代码下载超过1MB大小的文件,它正常工作.

图像不完整

预期的图像

scala

4
推荐指数
1
解决办法
5009
查看次数

在递归选项列表上播放延迟写入

如何准备(播放框架,scala)Json写了一个对象列表的选项,例如

case class Person(name: String, age: Int, relations: Option[List[Person]])
Run Code Online (Sandbox Code Playgroud)

我尝试了以下写作

implicit val personWrites: Writes[Person] = (
    (__ \ "name").write[String] and
    (__ \ "age").write[Int] and
    (__ \ "relations").lazyWrite[Option[Writes.traversableWrites[Person](personWrites)]])(unlift(Person.unapply))
Run Code Online (Sandbox Code Playgroud)

它无法正常工作,有人可以用正确的方式帮助我创建这些Json写入

json scala playframework playframework-2.0

3
推荐指数
1
解决办法
694
查看次数

ActionbarSherlock导航到新活动主页图标更改

与新的操作栏一样,当用户点击仪表板上的任何活动时,app会将用户带到新活动,同时操作栏中的主页图标会显示一个箭头,显示此活动已从其他活动启动.如何使用Sherlock安卓吧获得此功能?

android android-actionbar

0
推荐指数
1
解决办法
1603
查看次数