EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.store]

COVERAGE SUMMARY FOR SOURCE FILE [LobStorageRemoteInputStream.java]

nameclass, %method, %block, %line, %
LobStorageRemoteInputStream.java100% (1/1)60%  (3/5)71%  (77/109)74%  (20/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LobStorageRemoteInputStream100% (1/1)60%  (3/5)71%  (77/109)74%  (20/27)
read (): int 0%   (0/1)0%   (0/19)0%   (0/3)
read (byte []): int 0%   (0/1)0%   (0/7)0%   (0/1)
read (byte [], int, int): int 100% (1/1)89%  (47/53)79%  (11/14)
LobStorageRemoteInputStream (DataHandler, ValueLobDb, byte [], long): void 100% (1/1)100% (16/16)100% (6/6)
skip (long): long 100% (1/1)100% (14/14)100% (3/3)

1/*
2 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (http://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6package org.h2.store;
7 
8import java.io.IOException;
9import java.io.InputStream;
10 
11import org.h2.message.DbException;
12import org.h2.value.ValueLobDb;
13 
14/**
15 * An input stream that reads from a remote LOB.
16 */
17class LobStorageRemoteInputStream extends InputStream {
18 
19    /**
20     * The data handler.
21     */
22    private final DataHandler handler;
23 
24    /**
25     * The lob id.
26     */
27    private final long lob;
28 
29    private final byte[] hmac;
30 
31    /**
32     * The position.
33     */
34    private long pos;
35 
36    /**
37     * The remaining bytes in the lob.
38     */
39    private long remainingBytes;
40 
41    public LobStorageRemoteInputStream(DataHandler handler, ValueLobDb lob,
42            byte[] hmac, long byteCount) {
43        this.handler = handler;
44        this.lob = lob.getLobId();
45        this.hmac = hmac;
46        remainingBytes = byteCount;
47    }
48 
49    @Override
50    public int read() throws IOException {
51        byte[] buff = new byte[1];
52        int len = read(buff, 0, 1);
53        return len < 0 ? len : (buff[0] & 255);
54    }
55 
56    @Override
57    public int read(byte[] buff) throws IOException {
58        return read(buff, 0, buff.length);
59    }
60 
61    @Override
62    public int read(byte[] buff, int off, int length) throws IOException {
63        if (length == 0) {
64            return 0;
65        }
66        length = (int) Math.min(length, remainingBytes);
67        if (length == 0) {
68            return -1;
69        }
70        try {
71            length = handler.readLob(lob, hmac, pos, buff, off, length);
72        } catch (DbException e) {
73            throw DbException.convertToIOException(e);
74        }
75        remainingBytes -= length;
76        if (length == 0) {
77            return -1;
78        }
79        pos += length;
80        return length;
81    }
82 
83    @Override
84    public long skip(long n) {
85        remainingBytes -= n;
86        pos += n;
87        return n;
88    }
89 
90}

[all classes][org.h2.store]
EMMA 2.0.5312 (C) Vladimir Roubtsov