小编Abh*_*kar的帖子

如何限制Java应用程序中的Web服务使用?

假设我有一个Java服务器应用程序,它实现了一些Web服务.假设我也可以验证应用程序用户.

现在我想为每个用户添加一些服务使用限制:例如速率限制(每秒请求数),最大请求大小等.

Java中是否有"即用型"库可以做到这一点?

java security web-services rate-limiting

12
推荐指数
1
解决办法
2098
查看次数

无法捕获JsonMappingException

我的IDE给了我错误Unhandled Exception com.fasterxml.jackson.databind.JsonMappingExceptionmapper.readValue

ObjectMapper mapper = new ObjectMapper();
try {
    if (response.isEmpty()) {
        //Http 204 (No Content) returned from MCC
        //We should handle this differently
        user = new User();
    } else {
        user = mapper.readValue(response, User.class);
    }
} catch (IOException ioe) {
    logger.log(Level.SEVERE, ioe.getLocalizedMessage());
}
return user;
Run Code Online (Sandbox Code Playgroud)

我试过捕捉JsonMappingException它,但它没有让错误消失.有什么想法吗?

java jackson

10
推荐指数
2
解决办法
5704
查看次数

在defrecord构造函数中未强制执行类型提示

我使用defrecord字段类型提示创建了一个类型.但是,我发现这些类型的提示没有在构造函数中强制执行,我可以用它们做一些奇怪的事情.请查看下面的代码段,例如:

user=> (defrecord Person [#^String name #^Integer age])
user.Person
user=> (seq (.getConstructors Person))
(#<Constructor public user.Person(java.lang.Object,java.lang.Object,
java.lang.Object,java.lang.Object)>
#<Constructor public user.Person(java.lang.Object,java.lang.Object)>)
user=> (Person. (Integer. 123) "abhinav")
#:user.Person{:name 123, :age "abhinav"}
Run Code Online (Sandbox Code Playgroud)

显示的构造函数签名与提供的类型提示不匹配(它们Object用于StringInteger),我能够构造具有错误字段类型的对象.

我的代码有问题还是Clojure中的错误?

我在Clojure 1.2.0-beta1上.

clojure type-hinting

9
推荐指数
2
解决办法
2473
查看次数

FileOutputStream与ByteArrayOutputStream

我正在读别人的代码.这是它的要点.

类使用GZIPInputStream和GZIPOutputStream压缩和解压缩文件.

这是压缩过程中发生的事情的片段.inputFile并且outputFile是班级的实例File.

FileInputStream fis = new FileInputStream(inputFile);
GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(outputFile));

//the following function copies an input stream to an output stream
IOUtils.copy(fis,gzos);

//outputFile is the compressed file
...
Run Code Online (Sandbox Code Playgroud)

现在,这是解压过程中发生的事情.

GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(inputFile));
ByteArrayOutputStream baos = new ByteArrayOutputStream();

//copies input stream to output stream
IOUtils.copy(gzis,baos);

//this method does as its name suggests
FileUtils.writeByteArrayToFile(outputFile, baos.toByteArray());

//outputFile is the decompressed file
...
Run Code Online (Sandbox Code Playgroud)

原始程序员FileOutputStream在压缩ByteArrayOutputStream和解压缩过程中选择的原因是什么?这让我很困惑.

除非有充分的理由,否则我认为我正在改变它们,以避免将来混淆.这是一个好主意吗?

java file stream

9
推荐指数
2
解决办法
1万
查看次数

在scala中选择节点的所有子元素

我想选择名为"a"的节点的第一个孩子Elem.我现在得到的是:

(xml \ "a")(0).child.collect {case e: Elem => e}
Run Code Online (Sandbox Code Playgroud)

这非常冗长.我在寻找类似的东西:

xml \ "a" \ "*"
Run Code Online (Sandbox Code Playgroud)

这可能在scala中吗?

xml scala scala-xml

9
推荐指数
2
解决办法
5983
查看次数

在Scala中,有没有办法在Stream中获取当前评估的项目?

在Scala中,有没有办法在Stream中获取当前评估的项目?例如在Stream中

val s: Stream[Int] = Stream.cons(1, Stream.cons(2, Stream.cons(3, s.map(_+1))))
Run Code Online (Sandbox Code Playgroud)

该方法应该只返回List(1,2,3).

scala stream lazy-evaluation

7
推荐指数
2
解决办法
434
查看次数

递归流抛出StackOverflowError

我根据自身定义了一个流(一个递归定义).当试图访问流的第二个元素时,StackOverflowError抛出.来自scala控制台的代码:

scala> val s1 = Stream.iterate(1)(identity _)
s1: scala.collection.immutable.Stream[Int] = Stream(1, ?)

scala> lazy val s2 : Stream[Int]= Stream.cons(1, (s2, s1).zipped.map { _ + _ })
s2: Stream[Int] = <lazy>

scala> s1 take 5 print
1, 1, 1, 1, 1, empty
scala> s2(0)
res4: Int = 1

scala> s2(1)
java.lang.StackOverflowError
        at $anonfun$s2$1$$anonfun$apply$1.apply(<console>:9)
        at $anonfun$s2$1$$anonfun$apply$1.apply(<console>:9)
        at scala.Tuple2$Zipped$$anonfun$map$1.apply(Tuple2.scala:62)
        at scala.collection.immutable.Stream.foreach(Stream.scala:255)
        at scala.Tuple2$Zipped.map(Tuple2.scala:60)
        at $anonfun$s2$1.apply(<console>:9)
        at $anonfun$s2$1.apply(<console>:9)
        at scala.collection.immutable.Stream$Cons.tail(Stream.scala:556)
        at scala.collection.immutable.Stream$Cons.tail(Stream.scala:550)
        at scala.collection.immutable.Stream.foreach(Stream.scala:256)
        at scala.Tuple2$Zipped.map(Tuple2.scala:60)
        at $anonfun$s2$1.apply(<console>:9)
        at $anonfun$s2$1.apply(<console>:9)
        at scala.collection.immutable.Stream$Cons.tail(Stream.scala:556) …
Run Code Online (Sandbox Code Playgroud)

recursion scala stream lazy-evaluation scala-2.8

7
推荐指数
1
解决办法
1152
查看次数

从PDF中提取文本

我有一堆PDF文件,我需要转换为TXT.不幸的是,当我使用众多可用实用程序中的一个来执行此操作时,它会丢失所有格式,并且PDF中的所有列表数据都会混乱.是否可以使用Python通过指定位置等从PDF中提取文本?

谢谢.

python pdf

7
推荐指数
1
解决办法
2521
查看次数

是否有SQL语法感知Swing组件?

我正在寻找一些知道SQL语法的Java Swing组件(类似textarea) - 这意味着它可以识别并突出显示它.

如果没有,我将需要自己做,任何有用的建议如何不浪费太多时间(例如,使用哪个组件)?

java swing syntax-highlighting

7
推荐指数
1
解决办法
2580
查看次数

devanagari i18n in java

我正在尝试使用i18n在java中使用来自互联网的示例ttf文件的devanagari/hindi.

我能够加载资源包条目,并加载ttf和设置字体,但它不会根据需要呈现jlabel.它显示了代替字符的块.如果我在eclipse中调试,我可以将鼠标悬停在unicode变量上,甚至可以渲染devanagari.下面是代码和资源包供参考.

package i18n;

import java.awt.Font;
import java.awt.GridLayout;
import java.io.InputStream;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class MyNumbers extends JFrame {
    private ResourceBundle rb;
    private Font devanagariFont;

    public MyNumbers (String language, String fontFile) {
        loadResourceBundle(language);
        loadFont(fontFile);
        display();
    }

    private void display() {
        String unicode = null;

        JPanel labels = new JPanel(new GridLayout(0,2));
        JLabel uni = null;
        for(int i=0; i<=10; i++) {
            unicode = rb.getString("" +i);
            labels.add(new JLabel("" + i));
            labels.add(uni = new JLabel(unicode));
            uni.setFont(devanagariFont);
        } …
Run Code Online (Sandbox Code Playgroud)

java internationalization indic

7
推荐指数
1
解决办法
2716
查看次数