在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压缩后的数据解码、解压缩,最终还原为原始数据。