• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eXist-db / exist / 40657517912

28 Oct 2026 08:32AM UTC coverage: 58.121% (-0.08%) from 58.196%
40657517912

push

github

web-flow
Merge pull request #6938 from eXist-db/dependabot/github_actions/actions-0c219a018e

Bump docker/login-action from 4.6.0 to 4.7.0 in the actions group

32462 of 61752 branches covered (52.57%)

Branch coverage included in aggregate %.

85521 of 141244 relevant lines covered (60.55%)

2.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.66
/exist-core/src/main/java/org/exist/util/io/FileFilterInputStreamCache.java
1
/*
2
 * Copyright (c) 2012, Adam Retter
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *     * Redistributions of source code must retain the above copyright
8
 *       notice, this list of conditions and the following disclaimer.
9
 *     * Redistributions in binary form must reproduce the above copyright
10
 *       notice, this list of conditions and the following disclaimer in the
11
 *       documentation and/or other materials provided with the distribution.
12
 *     * Neither the name of Adam Retter Consulting nor the
13
 *       names of its contributors may be used to endorse or promote products
14
 *       derived from this software without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL Adam Retter BE LIABLE FOR ANY
20
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
package org.exist.util.io;
28

29
import java.io.IOException;
30
import java.io.InputStream;
31
import java.io.RandomAccessFile;
32
import java.nio.file.Path;
33

34
/**
35
 * Cache implementation for CachingFilterInputStream Backed by a Random Access
36
 * File
37
 *
38
 * Probably slower than MemoryMappedFileFilterInputStreamCache for multiple
39
 * reads, but uses a fixed small amount of memory.
40
 *
41
 * @version 1.1
42
 *
43
 * @author <a href="mailto:adam.retter@googlemail.com">Adam Retter</a>
44
 * @author <a href="tobi.krebsATgmail.com">Tobi Krebs</a>
45
 */
46
public class FileFilterInputStreamCache extends AbstractFilterInputStreamCache {
47
    private final Path tempFile;
48
    private final boolean externalFile;
49
    private int length = 0;
3 ✔
50
    private int offset = 0;
3 ✔
51

52
    private final RandomAccessFile raf;
53

54
    public FileFilterInputStreamCache(final InputStream src) throws IOException {
55
        this(src, null);
4 ✔
56
    }
1 ✔
57

58
    public FileFilterInputStreamCache(final InputStream src, final Path f) throws IOException {
59
        super(src);
3 ✔
60
        if(f == null) {
2 !
61
            tempFile = TemporaryFileManager.getInstance().getTemporaryFile();
4 ✔
62
            externalFile = false;
3 ✔
63
        } else {
1 ✔
64
            tempFile = f;
×
65
            externalFile = true;
×
66
        }
67

68
        this.raf = new RandomAccessFile(tempFile.toFile(), "rw"); //TODO(AR) consider moving to Files.newByteChannel(tempFile
9 ✔
69
    }
1 ✔
70

71
    @Override
72
    public void write(final byte[] b, final int off, final int len) throws IOException {
73
        //force writing to be append only
74
        if (offset != length) {
5 !
75
            raf.seek(length);
×
76
            offset = length;
×
77
        }
78

79
        raf.write(b, off, len);
6 ✔
80
        length += len;
6 ✔
81
        offset += len;
6 ✔
82
    }
1 ✔
83

84
    @Override
85
    public void write(final int i) throws IOException {
86
        //force writing to be append only
87
        if (offset != length) {
5 !
88
            raf.seek(length);
×
89
            offset = length;
×
90
        }
91

92
        raf.write(i);
4 ✔
93
        length++;
6 ✔
94
        offset++;
6 ✔
95
    }
1 ✔
96

97
    @Override
98
    public int getLength() {
99
        return length;
3 ✔
100
    }
101

102
    @Override
103
    public byte get(final int off) throws IOException {
104
        if (off != offset) {
4 ✔
105
            raf.seek(off);
5 ✔
106
            this.offset = off;
3 ✔
107
        }
108
        final byte b = raf.readByte();
4 ✔
109
        this.offset++;
6 ✔
110
        return b;
2 ✔
111
    }
112

113
    @Override
114
    public void copyTo(final int cacheOffset, final byte[] b, final int off, final int len) throws IOException {
115
        if (cacheOffset != offset) {
4 ✔
116
            raf.seek(cacheOffset);
5 ✔
117
            this.offset = cacheOffset;
3 ✔
118
        }
119
        raf.readFully(b, off, len);
6 ✔
120
        this.offset += len;
6 ✔
121
    }
1 ✔
122

123
    @Override
124
    public void invalidate() throws IOException {
125

126
        raf.close();
3 ✔
127

128
        if (tempFile != null && (!externalFile)) {
6 !
129
            TemporaryFileManager.getInstance().returnTemporaryFile(tempFile);
4 ✔
130
        }
131
    }
1 ✔
132

133
    /**
134
     * Get the path of the file backing the cache.
135
     *
136
     * @return the path of the file backing the cache.
137
     */
138
    public Path getFilePath() {
139
        return tempFile;
×
140
    }
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc