获取lseek失败:EBADF(错误文件编号)从InputStream读取位图时出现异常

时间:2014-12-11 06:19:36

标签: android bitmap inputstream android-bitmap

我得到" lseek失败:从InputStream创建位图时出现EBADF(错误的文件编号)异常" 问题。此问题仅在某些特定设备中出现。对我来说,我在" Nexus 5"中得到了这个错误。设备和我的客户在" Samsung S3"设备。我在三星s3设备上没有遇到这个问题。问题类似于link1link2

但我无法调试并解决此问题。下面是我读取输入流和位图的代码。

InputStream in = getImageStream(index);

 public InputStream getRawImageStream(long position) throws IOException {
    super.seek(position);
    long length = super.readLong();
    LOG.debug("getRawImageStream(0x%x) len:%,d", position, length);
    if (length > MAX_IMAGE_SIZE) {
        throw new IOException(String.format("Excessive image length %,d", length));
    }
    return new RandomAccessFileInputStream(this, length);
}

public static long copy(InputStream input, OutputStream output, long length) throws IOException {
    byte[] buffer = new byte[BUFFER_SIZE];
    long count = 0;
    int n = 0;
    int chunk = BUFFER_SIZE;
    while (count < length) {
        if (count + chunk > length) {
            chunk = (int) (length - count);
        }
        if (-1 == (n = input.read(buffer, 0, chunk))) {
            break;
        }
        output.write(buffer, 0, n);
        count += n;
    }
    return count;

}

@Override
public int read(byte[] b, int off, int len) throws IOException {
    long alen = Math.min(len, endPosition - file.getFilePointer());
    if (len <= 0) {
        // At end of stream / section
        return END_OF_SECTION;
    }
    return this.file.read(b, off, (int) alen);
}

请检查我的代码,让我知道你的想法。任何帮助都会受到高度关注。

0 个答案:

没有答案