使用问题的base64 EN coder和InputStreamReader的 [英] problem using base64 encoder and InputStreamReader

查看:119
本文介绍了使用问题的base64 EN coder和InputStreamReader的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个数据库中的一些CLOB列,我需要把Base64的EN codeD二进制文件英寸
这些文件可以是大的,所以我需要串流,我不能读了整个事情的一次。

I have some CLOB columns in a database that I need to put Base64 encoded binary files in. These files can be large, so I need to stream them, I can't read the whole thing in at once.

我用 org.apache.commons。codec.binary.Base64InputStream 做编码,和我遇到的一个问题。我的code基本上是这种

I'm using org.apache.commons.codec.binary.Base64InputStream to do the encoding, and I'm running into a problem. My code is essentially this

FileInputStream fis = new FileInputStream(file);
Base64InputStream b64is = new Base64InputStream(fis, true, -1, null);
BufferedReader reader = new BufferedReader(new InputStreamReader(b64is));

preparedStatement.setCharacterStream(1, reader);

当我运行上面的code,我得到其中的一个更新的执行过程中
java.io.IOException异常:基本输入流返回零字节,它被深藏在InputStreamReader的code抛出

When I run the above code, I get one of these during the execution of the update java.io.IOException: Underlying input stream returned zero bytes, it is thrown deep in the InputStreamReader code.

为什么会这样不行?在我看来,像将尝试从基地64个流,这会从文件流中读取阅读,一切都应该是快乐的。

Why would this not work? It seems to me like the reader would attempt to read from the base 64 stream, which would read from the file stream, and everything should be happy.

推荐答案

这似乎是在 Base64InputStream 的错误。你正确地调用它。

This appears to be a bug in Base64InputStream. You're calling it correctly.

您应该将此情况报告给了Apache公地codeC项目。

You should report this to the Apache commons codec project.

简单的测试用例:

import java.io.*;
import org.apache.commons.codec.binary.Base64InputStream;

class tmp {
  public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream(args[0]);
    Base64InputStream b64is = new Base64InputStream(fis, true, -1, null);

    while (true) {
      byte[] c = new byte[1024];
      int n = b64is.read(c);
      if (n < 0) break;
      if (n == 0) throw new IOException("returned 0!");
      for (int i = 0; i < n; i++) {
        System.out.print((char)c[i]);
      }
    }
  }
}

读(字节[])的InputStream 不允许返回0调用它返回0其上是3个字节的倍数的任何文件长

the read(byte[]) call of InputStream is not allowed to return 0. It does return 0 on any file which is a multiple of 3 bytes long.

这篇关于使用问题的base64 EN coder和InputStreamReader的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆