解决package:java.nio.charset.MalformedInputException: Input length = 1异常

目录

一、问题重现

二、解决思路

三、最终解决


一、问题重现

        今天本地idea在多模块Maven:package时出现java.nio.charset.MalformedInputException: Input length = 1异常,Maven:clean正常。

二、解决思路

        起初百度说是File Encodings设置成UTF-8后,启动会正常。

        设置完毕后,重新package工程还是报同样的错误信息,细细观察后发现,因为项目使用了nacos管理、读取配置文件,而在配置文件中“# mybatis-plus****”后面是中文注释,但是现在乱码了,所以会不会是package过程中解析远程nacos中的配置文件时出现了问题,那么如果项目没有使用nacos,上述File Encodings方法修改后是不是会启动成功(未尝试)。

        结合网上说大概率是yml中中文备注的原因,所以先将nacos配置文件的中文注释全都删除 (后面有更简便方法,切勿着急删除配置中文注释!!!)。

        再次package项目工程时成功了。

三、最终解决

        配置文件增加注释就是方便咱们理解配置作用,现在给全删了肯定不便以后阅读,所以咱们也可以在父类pom.xml文件中增加配置<argLine>-Dfile.encoding=UTF-8</argLine>,启动项目后也能够正常打包!

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <testFailureIgnore>true</testFailureIgnore>
					<!-- 定义文件编码,否则nacos配置文件中存在中文会报错 -->
          <argLine>-Dfile.encoding=UTF-8</argLine>
        </configuration>
      </plugin>
    </plugins>
  </build>
### MD5 Hashing Implementation in Java In Java, implementing MD5 hashing involves using the `MessageDigest` class from the `java.security` package. This class provides methods to generate message digests based on various algorithms including MD5. Below is an example demonstrating how to compute the MD5 hash of a string: ```java import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5Example { public static String getMD5(String input) { try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes(StandardCharsets.UTF_8)); StringBuilder hexString = new StringBuilder(); for (byte b : messageDigest) { String hex = Integer.toHexString(0xff & b); if (hex.length() == 1) { hexString.append('0'); } hexString.append(hex); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); // Handle exception according to your application requirements. } } public static void main(String[] args) { String password = "password"; System.out.println("MD5 Hash: " + getMD5(password)); // Output will be the MD5 hash value of 'password'. } } ``` This program defines a method named `getMD5`, which takes a string as its parameter and returns the corresponding MD5 hash value represented as a hexadecimal string[^6]. The process includes obtaining an instance of the `MessageDigest` with the specified algorithm ("MD5"), digesting the bytes of the provided text encoded in UTF-8 format, converting each byte into two-digit hexadecimal representation, concatenating them together, and finally returning this concatenated result. It should also be noted that while MD5 remains widely used due to performance considerations or legacy reasons, it has been proven insecure against collision attacks since at least 2004[^7], making stronger alternatives like SHA-256 preferable when security concerns arise.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值