在Java中,可以使用Base64類進行編碼和解碼操作。要解碼Base64壓縮后的數據并還原為原始數據,可以按照以下步驟進行操作:
import java.util.Base64;
String compressedBase64Data = "c29tZSBkYXRhIHdpdGggYmFzZTY0Lg==";
byte[] compressedData = Base64.getDecoder().decode(compressedBase64Data);
ByteArrayInputStream inputStream = new ByteArrayInputStream(compressedData);
GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = gzipInputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
}
byte[] decompressedData = outputStream.toByteArray();
String originalData = new String(decompressedData, StandardCharsets.UTF_8);
System.out.println(originalData);
通過以上步驟,就可以將Base64壓縮后的數據解碼、解壓縮,最終還原為原始數據。