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

bernardladenthin / BitcoinAddressFinder / #327

06 Jun 2025 10:36PM UTC coverage: 65.407% (-0.7%) from 66.078%
#327

push

bernardladenthin
refactor: simplify Bech32 detection and fallback, add tests for invalid addresses

4 of 4 new or added lines in 1 file covered. (100.0%)

8 existing lines in 3 files now uncovered.

1246 of 1905 relevant lines covered (65.41%)

0.65 hits per line

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

65.38
/src/main/java/net/ladenthin/bitcoinaddressfinder/AbstractPlaintextFile.java
1
// @formatter:off
2
/**
3
 * Copyright 2021 Bernard Ladenthin bernard.ladenthin@gmail.com
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *    http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
// @formatter:on
19
package net.ladenthin.bitcoinaddressfinder;
20

21
import java.io.File;
22
import java.io.IOException;
23
import java.io.RandomAccessFile;
24
import java.nio.charset.StandardCharsets;
25
import java.util.concurrent.atomic.AtomicBoolean;
26
import org.jspecify.annotations.NonNull;
27
import org.lmdbjava.LmdbException;
28

29
public abstract class AbstractPlaintextFile implements Interruptable {
30
    
31
    @NonNull
32
    protected final File file;
33
    @NonNull
34
    protected final ReadStatistic readStatistic;
35
    @NonNull
1✔
36
    private final AtomicBoolean shouldRun = new AtomicBoolean(true);
37
    
38
    public AbstractPlaintextFile(@NonNull File file, @NonNull ReadStatistic readStatistic) {
1✔
39
        this.file = file;
1✔
40
        this.readStatistic = readStatistic;
1✔
41
    }
1✔
42
    
43
    protected double calculateFileProgress(@NonNull RandomAccessFile raf) throws IOException {
44
        return ((double)(Math.max(raf.getFilePointer(),1)) / (double)raf.length()) * 100.0d;
1✔
45
    }
46
    
47
    protected abstract void processLine(String line);
48
    
49
    public void readFile() throws IOException {
50
        try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
1✔
51
            while(shouldRun.get()) {
1✔
52
                String line = raf.readLine();
1✔
53
                if (line == null) {
1✔
54
                    return;
1✔
55
                }
56
                String utf8 = new String(line.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
1✔
57
                readStatistic.currentFileProgress = calculateFileProgress(raf);
1✔
58
                try {
59
                    processLine(utf8);
1✔
60
                } catch(LmdbException e) {
×
61
                    // do not catch expections from LMDB (e. g. MapFullException).
62
                    throw e;
×
UNCOV
63
                } catch (Exception e) {
×
UNCOV
64
                    System.err.println("Error in line: " + utf8);
×
UNCOV
65
                    e.printStackTrace();
×
UNCOV
66
                    readStatistic.errors.add(utf8);
×
67
                }
1✔
68
            }
1✔
69
        }
1✔
70
    }
×
71

72
    @Override
73
    public void interrupt() {
74
        shouldRun.set(false);
×
75
    }
×
76
    
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc