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

devonfw / IDEasy / 13788578520

11 Mar 2025 12:57PM UTC coverage: 67.476% (-1.1%) from 68.619%
13788578520

Pull #1025

github

web-flow
Merge ae2f75eb8 into 2cf68279f
Pull Request #1025: #1024: Move urls into url-updater module

3034 of 4915 branches covered (61.73%)

Branch coverage included in aggregate %.

7798 of 11138 relevant lines covered (70.01%)

3.06 hits per line

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

6.06
cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlChecksum.java
1
package com.devonfw.tools.ide.url.model.file;
2

3
import java.io.BufferedWriter;
4
import java.io.IOException;
5
import java.nio.file.Files;
6
import java.nio.file.Path;
7
import java.nio.file.StandardOpenOption;
8
import java.util.Iterator;
9
import java.util.Objects;
10

11
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
12
import com.devonfw.tools.ide.util.SingleElementIterator;
13

14
/**
15
 * {@link AbstractUrlFile} for the checksum of a binary download file.
16
 */
17
public class UrlChecksum extends AbstractUrlFile<UrlVersion> implements UrlGenericChecksum, UrlChecksums {
18

19
  /** The file extension of the checksum file (including the dot). */
20
  public static final String EXTENSION = ".sha256";
21

22
  /** The hash algorithm to use ({@value}). */
23
  public static final String HASH_ALGORITHM = "SHA-256";
24

25
  private String checksum;
26

27
  /**
28
   * The constructor.
29
   *
30
   * @param parent the {@link #getParent() parent folder}.
31
   * @param name the {@link #getName() filename}.
32
   */
33
  public UrlChecksum(UrlVersion parent, String name) {
34

35
    super(parent, name);
4✔
36
  }
1✔
37

38
  @Override
39
  public String getChecksum() {
40

41
    load(false);
×
42
    return this.checksum;
×
43
  }
44

45
  /**
46
   * @param checksum the new value of {@link #getChecksum()}.
47
   */
48
  public void setChecksum(String checksum) {
49

50
    if (Objects.equals(this.checksum, checksum)) {
×
51
      return;
×
52
    }
53
    this.checksum = checksum;
×
54
    this.modified = true;
×
55
  }
×
56

57
  @Override
58
  public String getHashAlgorithm() {
59

60
    return HASH_ALGORITHM;
×
61
  }
62

63
  @Override
64
  protected void doLoad() {
65

66
    Path path = getPath();
×
67
    try {
68
      String cs = Files.readString(path).trim();
×
69
      setChecksum(cs);
×
70
    } catch (IOException e) {
×
71
      throw new IllegalStateException("Failed to load file " + path, e);
×
72
    }
×
73
  }
×
74

75
  @Override
76
  protected void doSave() {
77

78
    if ((this.checksum == null) || this.checksum.isEmpty()) {
×
79
      return;
×
80
    }
81
    Path path = getPath();
×
82
    try (BufferedWriter bw = Files.newBufferedWriter(path, StandardOpenOption.TRUNCATE_EXISTING,
×
83
        StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
84
      bw.write(this.checksum + "\n");
×
85

86
    } catch (IOException e) {
×
87
      throw new IllegalStateException("Failed to save file " + path, e);
×
88
    }
×
89
  }
×
90

91
  @Override
92
  public Iterator<UrlGenericChecksum> iterator() {
93

94
    return new SingleElementIterator<>(this);
×
95
  }
96

97
}
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

© 2025 Coveralls, Inc