protected static String base64GZIPDecoder(String value) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(value.getBytes(UTF_8)); try (InputStream b64is = Base64.getDecoder().wrap(bais); // InputStream gzis = new GZIPInputStream(b64is)) { return IOUtils.toString(gzis, UTF_8); } }
//Convert Based64, unzip to xml in stream (strLista is list of Base64 bytes ByteArrayInputStream in = new ByteArrayInputStream(strLista.getBytes()); try(InputStream reader = Base64.getMimeDecoder().wrap(in)){ try (GZIPInputStream gis = new GZIPInputStream(reader)) { try (ByteArrayOutputStream out = new ByteArrayOutputStream()){ int readGis = 0; while ((readGis = gis.read(buff)) > 0) out.write(buff, 0, readGis);
FileInputStream inputStream = new FileInputStream(input); FileOutputStream outputStream = new FileOutputStream(output); OutputStream decodedStream = Base64.getDecoder().wrap(outputStream);
InputStream decodedIs = Base64.getDecoder().wrap(vars.peaksChars); InflaterInputStream iis = null; DataInputStream peakStream = null;
InputStream decodedIs = Base64.getDecoder().wrap(vars.peaksChars); InflaterInputStream iis = null; DataInputStream peakStream = null;
@Override public Image call() throws Exception { try (InputStream imageStream = Base64.getDecoder().wrap(pipedInput)) {
getIntensityBinaryDataInfo().getPosition(), getIntensityBinaryDataInfo().getEncodedLength()); InputStream decodedIs = Base64.getDecoder().wrap(encodedIs); byte[] decodedData = IOUtils.toByteArray(decodedIs); System.out.println(new String(IOUtils.toByteArray(encodedIs)));
InputStream decodedIs = Base64.getDecoder().wrap(encodedIs); byte[] decodedData = IOUtils.toByteArray(decodedIs);
@Override public BlockInformation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (!json.isJsonObject()) { return null; } JsonObject jsonRoot = json.getAsJsonObject(); BlockPos position = new BlockPos(jsonRoot.get("x").getAsInt(), jsonRoot.get("y").getAsInt(), jsonRoot.get("z").getAsInt()); Block block = Block.getBlockFromName(jsonRoot.get("block").getAsString()); int meta = 0; if(jsonRoot.has("meta")) { meta = jsonRoot.get("meta").getAsInt(); } NBTTagCompound nbt = null; if(jsonRoot.has("nbt")) { InputStream is = new ByteArrayInputStream(jsonRoot.get("nbt").getAsString().getBytes(StandardCharsets.UTF_8)); InputStream wrappedIs = Base64.getDecoder().wrap(is); try { nbt = CompressedStreamTools.readCompressed(wrappedIs); } catch (IOException e) { } } boolean writePositionData = !jsonRoot.has("skipPositionData"); return new BlockInformation(position, block, meta, nbt, writePositionData); } }
public PlistPartition[] getPartitions() throws IOException { LinkedList<PlistPartition> partitionList = new LinkedList<PlistPartition>(); PlistNode current = getRootNode(); current = current.cd("dict"); current = current.cdkey("resource-fork"); current = current.cdkey("blkx"); // Variables to keep track of the pointers of the previous partition long previousOutOffset = 0; long previousInOffset = 0; // Iterate over the partitions and gather data for (PlistNode pn : current.getChildren()) { String partitionName = io.takari.jdkget.osx.util.Util.readFully(pn.getKeyValue("Name")); String partitionID = io.takari.jdkget.osx.util.Util.readFully(pn.getKeyValue("ID")); String partitionAttributes = io.takari.jdkget.osx.util.Util.readFully(pn.getKeyValue("Attributes")); Reader base64Data = pn.getKeyValue("Data"); InputStream base64DataInputStream = Base64.getMimeDecoder().wrap(new ReaderInputStream(base64Data, Charset.forName("US-ASCII"))); PlistPartition dpp = new PlistPartition(partitionName, partitionID, partitionAttributes, base64DataInputStream, previousOutOffset, previousInOffset); previousOutOffset = dpp.getFinalOutOffset(); previousInOffset = dpp.getFinalInOffset(); partitionList.addLast(dpp); } return partitionList.toArray(new PlistPartition[partitionList.size()]); } }
@Override public InputStream getFile(String setting) throws GeneralSecurityException { KeyStore.Entry entry = keystore.get().getEntry(setting, keystorePassword.get()); if (settingTypes.get(setting) != KeyType.FILE || entry instanceof KeyStore.SecretKeyEntry == false) { throw new IllegalStateException("Secret setting " + setting + " is not a file"); } KeyStore.SecretKeyEntry secretKeyEntry = (KeyStore.SecretKeyEntry) entry; PBEKeySpec keySpec = (PBEKeySpec) fileFactory.getKeySpec(secretKeyEntry.getSecretKey(), PBEKeySpec.class); // The PBE keyspec gives us chars, we first convert to bytes, then decode base64 inline. char[] chars = keySpec.getPassword(); byte[] bytes = new byte[chars.length]; for (int i = 0; i < bytes.length; ++i) { bytes[i] = (byte)chars[i]; // PBE only stores the lower 8 bits, so this narrowing is ok } keySpec.clearPassword(); // wipe the original copy InputStream bytesStream = new ByteArrayInputStream(bytes) { @Override public void close() throws IOException { super.close(); Arrays.fill(bytes, (byte)0); // wipe our second copy when the stream is exhausted } }; return Base64.getDecoder().wrap(bytesStream); }
/** * Get the original string from its compressed base64 representation. * @param base64CompressedString Compressed Base64 representation of the string. * @return The original string. * @throws NullPointerException If base64CompressedString is null. * @throws IllegalArgumentException If base64CompressedString is not null, but has a length of zero or if the input is invalid. */ @SneakyThrows(IOException.class) public static String decompressFromBase64(final String base64CompressedString) { Exceptions.checkNotNullOrEmpty(base64CompressedString, "base64CompressedString"); try { @Cleanup final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(base64CompressedString.getBytes(UTF_8)); @Cleanup final InputStream base64InputStream = Base64.getDecoder().wrap(byteArrayInputStream); @Cleanup final GZIPInputStream gzipInputStream = new GZIPInputStream(base64InputStream); return IOUtils.toString(gzipInputStream, UTF_8); } catch (ZipException | EOFException e) { // exceptions thrown for invalid encoding and partial data. throw new IllegalArgumentException("Invalid base64 input.", e); } }
private void fromBase64(String src, OutputStream target) throws IOException { InputStream bytes = new ByteBufferBackedInputStream(StandardCharsets.ISO_8859_1.encode(src)); copy(Base64.getDecoder().wrap(bytes), target); }
@Override public final Object aroundReadFrom(ReaderInterceptorContext context) throws IOException { if (isBase64(context)) { context.setInputStream(Base64.getDecoder().wrap(context.getInputStream())); } return context.proceed(); }