小编cod*_*ler的帖子

在CipherInputStream中跳过方法

我遇到了一个问题,如果使用CipherInputStream,那么对FileInputStream支持的InputStream工作的代码不起作用.

示例如下:

  // skipCount is same as n in a FileInputStream
  FileInputStream fis;
  ... 
  skipCount = fis.skip(n)
Run Code Online (Sandbox Code Playgroud)

如果使用CipherInputStream,则获取不同的行为

  // skipCount is always 0
  CipherInputStream cis;
  ...
  skipCount = cis.skip(n)
Run Code Online (Sandbox Code Playgroud)

在进一步调试之后看起来,如果与read()调用一起使用,skip将仅起作用(即,返回值> 0).

有没有更好的方法来跳过使用CipherInputStream,而不是滚动自己的"skip"方法依赖于调用read?

另外,有没有办法告诉CipherInputStream自动执行"读取"作为调用跳过调用的一部分?否则,看起来跳过API在CipherInputStream中是不稳定的.

MCVE

public class TestSkip {
  public static final String ALGO = "AES/CBC/PKCS5Padding";
  public static final String CONTENT = "Strive not to be a success, but rather to be of value";
  private static int BlockSizeBytes = 16;
  private static SecureRandom random = null;

  static {
    try {
      random …
Run Code Online (Sandbox Code Playgroud)

java file-io cryptography inputstream

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

Java 8中的Maven错误

使用Maven和Java 8获取错误(jdk1.8.0_45).Java 7不会发生此问题.

MCVE

创建一个示例maven项目.例如:

mvn archetype:create -DgroupId=testinovke -DartifactId=testinvoke
Run Code Online (Sandbox Code Playgroud)

在生成的App.java文件中创建以下内容

package testinovke;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class App {

    public static MethodHandles.Lookup lookup;

    public static class Check {
        public void primitive(final int i){
        }
        public void wrapper(final Integer i){
        }
    }


    public static void main(String[] args) throws Throwable {
        Check check = new Check();

        MethodType type = MethodType.methodType(void.class, int.class);

        MethodHandle mh = lookup.findVirtual(Check.class, "primitive", type);
        mh.invoke();
    }
}
Run Code Online (Sandbox Code Playgroud)

编译maven项目:

mvn clean compile
Run Code Online (Sandbox Code Playgroud)

产量

收到以下错误:

testinvoke/src/main/java/testinovke/App.java:[25,18] method invoked …
Run Code Online (Sandbox Code Playgroud)

java maven java-8

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

标签 统计

java ×2

cryptography ×1

file-io ×1

inputstream ×1

java-8 ×1

maven ×1