Add file that the standalone Jar should be ran and not extracted; Remove lombok docum...
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / general / JavaDocFile.java
blob497887634878e758129c7b5a271457f5a2c48fd2
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.plugin.general;
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.security.MessageDigest;
15 import java.security.NoSuchAlgorithmException;
17 /**
18 * Represents the JavaDoc file.
20 * @since 2022/08/29
22 public final class JavaDocFile
23 implements Comparable<JavaDocFile>
25 /** The name of the file. */
26 public final String name;
28 /** The data supplier. */
29 public final JavaDocFileSupplier supplier;
31 /** The checksum. */
32 private volatile byte[] _checksum;
34 /**
35 * Initializes the file reference.
37 * @param __name The name of the file.
38 * @param __supplier The supplier for the file data.
39 * @throws NullPointerException On null arguments.
40 * @since 2022/08/29
42 public JavaDocFile(String __name, JavaDocFileSupplier __supplier)
43 throws NullPointerException
45 if (__name == null || __supplier == null)
46 throw new NullPointerException("NARG");
48 this.name = __name;
49 this.supplier = __supplier;
52 /**
53 * Returns the checksum of the file.
55 * @return The file checksum.
56 * @since 2022/08/29
58 public byte[] checkSum()
60 // Has this already been calculated?
61 byte[] checksum = this._checksum;
62 if (checksum != null)
63 return checksum.clone();
65 // Calculate it
66 try (InputStream in = this.supplier.open())
68 MessageDigest digest = MessageDigest.getInstance("sha-1");
70 // Calculate checksum with bytes
71 byte[] buf = new byte[16384];
72 for (;;)
74 int rc = in.read(buf);
76 if (rc < 0)
77 break;
79 digest.update(buf, 0, rc);
82 checksum = digest.digest();
83 this._checksum = checksum;
84 return checksum.clone();
86 catch (IOException|NoSuchAlgorithmException e)
88 throw new RuntimeException(e);
92 /**
93 * {@inheritDoc}
94 * @since 2022/08/29
96 @Override
97 public int compareTo(JavaDocFile __b)
99 return this.name.compareTo(__b.name);
103 * {@inheritDoc}
104 * @since 2022/08/29
106 @Override
107 public String toString()
109 return this.name;