base64解码

@param base64 被解码的base64字符串
@param destFile 目标文件
@return 目标文件
@since 4.0.9
974552
public static File decodeToFile(String base64, File destFile) {
		return FileUtil.writeBytes(Base64Decoder.decode(base64), destFile);
	}
876728
public static Attachment fromBase64( String base64encodedContent, MediaType mediaType ) {
        if( !mediaType.isBinary() ) {
            throw new IllegalArgumentException( "MediaType must be binary" );
        }
        return new Attachment( base64encodedContent, mediaType );
    }
867388
function getImageSizeFromFile(file) {
	return new Promise((resolve, reject) => {
		const isDataUrl = file.match(/^data:.+?;base64,/);

		if (isDataUrl) {
			// NB should use sync version of `sizeOf()` for buffers
			try {
				const data = Buffer.from(file.slice(isDataUrl[0].length), 'base64');
				return resolve(sizeForFileName('', sizeOf(data)));
			} catch (err) {
				return reject(err);
			}
		}

		sizeOf(file, (err, size) => {
			if (err) {
				reject(err);
			} else {
				resolve(sizeForFileName(path.basename(file), size));
			}
		});
	});
}
1314130
def load_file_to_base64_str(f_path):
    
    path = abs_path(f_path)
    with io.open(path, 'rb') as f:
        f_bytes = f.read()
        base64_str = base64.b64encode(f_bytes).decode("utf-8")
        return base64_str
691392
public static String bytesToBase64Str(byte[] bytes) {
        if (ArrayUtils.isEmpty(bytes)) {
            return null;
        }
        Base64.Encoder encoder = Base64.getEncoder();
        String base64Str = encoder.encodeToString(bytes);
        return base64Str;
    }
589940
public static String decodeBase64(String content, Charset charset, TestContext context) {
        return new DecodeBase64Function().execute(Arrays.asList(content, charset.displayName()), context);
    }
187740
def decodedFileID(self, cachedFilePath):
        
        fileDir, fileName = os.path.split(cachedFilePath)
        assert fileDir == self.localCacheDir, 'Can\'t decode uncached file names'
        # We encode and decode here because base64 can't work with unencoded text
        # Its probably worth, later, converting all file name variables to bytes
        # and not text.
        return base64.urlsafe_b64decode(fileName.encode('utf-8')).decode('utf-8')
639573
public static void decodeAndSetFileData(final File file, final String rawData) throws FrameworkException, IOException {

		Base64URIData uriData = new Base64URIData(rawData);
		setFileData(file, uriData.getBinaryData(), uriData.getContentType(), true);
	}
882586
@Deprecated
    public static String encodeBASE64(String value) {
        return new String(Base64.encode(value.getBytes(Charsets.UTF_8)));
    }
274180
public String getPublicKeyBase64() {
		final PublicKey publicKey = getPublicKey();
		return (null == publicKey) ? null : Base64.encode(publicKey.getEncoded());
	}
932407
def debase64(byte_str):
    
    # Python 3: base64.b64decode() expects type byte
    if isinstance(byte_str, str) and not PYTHON2:
        byte_str = bytes(byte_str, 'utf-8')
    return base64.b64decode(byte_str)
737317
def binary2base64(binary_file: str) -> str:
    
    # Use mode = "rb" to read binary file
    with open(binary_file, "rb") as bin_file:
        encoded_string = base64.b64encode(bin_file.read())
    return encoded_string.decode()
954142
public static void decodeFileToFile(String infile, String outfile) throws IOException {
		byte[] decoded = Base64.decodeFromFile(infile);
		java.io.OutputStream out = null;
		try{
			out = new java.io.BufferedOutputStream(new FileOutputStream(outfile));
			out.write(decoded);
		} catch (IOException e) {
			throw e; // Catch and release to execute finally{}
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (Exception ex) {
			}
		}
	}
1203198
def read_as_base64(fn):
    
    with open(fn) as unpacked_file:
        with tempfile.TemporaryFile() as b64_file:
            base64.encode(unpacked_file, b64_file)
            b64_file.flush()

            b64_file.seek(0)
            return b64_file.read()
804578
static String base64(byte[] data) {
        ByteBuf encodedData = Unpooled.wrappedBuffer(data);
        ByteBuf encoded = Base64.encode(encodedData);
        String encodedString = encoded.toString(CharsetUtil.UTF_8);
        encoded.release();
        return encodedString;
    }
886635
public static boolean copyToFile(InputStream inputStream, File destFile) {
        try {
            OutputStream out = new FileOutputStream(destFile);
            try {
                byte[] buffer = new byte[4096];
                int bytesRead;
                while ((bytesRead = inputStream.read(buffer)) >= 0) {
                    out.write(buffer, 0, bytesRead);
                }
            } finally {
                out.close();
            }
            return true;
        } catch (IOException e) {
            return false;
        }
    }
756812
public static void copyFile(File srcFile, File destFile) throws IOException
    {
        InputStream reader = new FileInputStream(srcFile);
        OutputStream out = new FileOutputStream(destFile);
        try
        {
            byte[] buffer = new byte[2048];
            int n = 0;
            while (-1 != (n = reader.read(buffer))) 
            {
                out.write(buffer, 0, n);
            } 
        }
        finally
        {
            org.apache.commons.io.IOUtils.closeQuietly(out);
            org.apache.commons.io.IOUtils.closeQuietly(reader);
        }
    }