kar*_*rts 7 java base64 encoding jdbc inputstreamreader
我在数据库中有一些CLOB列,我需要将Base64编码的二进制文件放入.这些文件可能很大,所以我需要流式传输它们,我无法立即读取整个内容.
我正在使用org.apache.commons.codec.binary.Base64InputStream编码,我遇到了问题.我的代码基本上就是这个
FileInputStream fis = new FileInputStream(file);
Base64InputStream b64is = new Base64InputStream(fis, true, -1, null);
BufferedReader reader = new BufferedReader(new InputStreamReader(b64is));
preparedStatement.setCharacterStream(1, reader);
当我运行上面的代码时,我在执行更新期间得到其中一个代码,
 java.io.IOException: Underlying input stream returned zero bytes它在InputStreamReader代码中被深深抛出.
为什么这不起作用?在我看来,它reader会尝试从基本的64流中读取,这将从文件流中读取,并且一切都应该是快乐的.
Kei*_*all 14
这似乎是一个错误Base64InputStream.你正确地调用它.
您应该将此报告给Apache commons编解码器项目.
简单的测试案例:
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]);
      }
    }
  }
}
所述read(byte[])的呼叫InputStream不允许返回0.它在其上是3个字节的倍数长的任何文件返回0.
| 归档时间: | 
 | 
| 查看次数: | 9554 次 | 
| 最近记录: |