1 inputsteam to Base64
/**
* InputStream to Base64
*
* @param inputStream
* @return
*/
public static String toBase64(InputStream inputStream) {
try {
//switch to base64
byte[] bytes = IOUtils.toByteArray(inputStream);
return Base64.getEncoder().encodeToString(bytes);
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
2 debugging code
/**
* get Base64
*
* @return
* @throws IOException
*/
@GetMapping("/getBase64")
public String getBases64() throws IOException {
InputStream inputStream = new ClassPathResource("/img/logo.jpg").getInputStream();
return toBase64(inputStream);
}
3 picture address
4 debugging results
Read More:
- The thread implementation of timer in Java
- Implementation of retrial mechanism in Java
- Java: How to use itext to export PDF text absolute positioning (implementation method)
- Java callback function implementation case
- [Solved] BASE64Encoder Error: Cannot resolve symbol ‘BASE64Encoder’
- How to Fix Error Caused by: java.util.MissingResourceException: Can‘t find bundle for base name xxx, locale zh_CN
- [Solved] IDEA Error(15, 16) java Program Pack sun.misc does not exsit or import sun.misc.BASE64Decoder Cannot find
- [Solved] Project Error: Could not found sun.misc.BASE64Encoder
- Java learning unreported exception java.io.IOException ; must be caught or declared to be thrown
- C++: Implementation of multi-channel IO transfer with select
- [Solved] GRPC-Server Error: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String; CLjava
- C language: Implementation of dynamic array initialization, insertion, traversal, deletion and destruction
- The java springboot websocket service server actively closes the connection and causes java.io.EOFException to be thrown
- [Solved] The Bean Validation API is on the classpath but no implementation could be found
- [PROJECT] itdage java to get the weather and send text messages
- [Solved] Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- JAVA: How to Use Minio to upload pictures
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- How to Solve java server error (java application Run Normally)
- [Solved] Java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to java.util.List