本文整理汇总了Java中com.lowagie.text.pdf.codec.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于com.lowagie.text.pdf.codec包,在下文中一共展示了Base64类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTSAResponse
import com.lowagie.text.pdf.codec.Base64; //导入依赖的package包/类
/**
* Get timestamp token - communications layer
* @return - byte[] - TSA response, raw bytes (RFC 3161 encoded)
*/
protected byte[] getTSAResponse(byte[] requestBytes) throws Exception {
// Setup the TSA connection
URL url = new URL(tsaURL);
URLConnection tsaConnection;
tsaConnection = (URLConnection) url.openConnection();
tsaConnection.setDoInput(true);
tsaConnection.setDoOutput(true);
tsaConnection.setUseCaches(false);
tsaConnection.setRequestProperty("Content-Type", "application/timestamp-query");
//tsaConnection.setRequestProperty("Content-Transfer-Encoding", "base64");
tsaConnection.setRequestProperty("Content-Transfer-Encoding", "binary");
if ((tsaUsername != null) && !tsaUsername.equals("") ) {
String userPassword = tsaUsername + ":" + tsaPassword;
tsaConnection.setRequestProperty("Authorization", "Basic " + Base64.encodeBytes(userPassword.getBytes()));
}
OutputStream out = tsaConnection.getOutputStream();
out.write(requestBytes);
out.close();
// Get TSA response as a byte array
InputStream inp = tsaConnection.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = inp.read(buffer, 0, buffer.length)) >= 0) {
baos.write(buffer, 0, bytesRead);
}
byte[] respBytes = baos.toByteArray();
String encoding = tsaConnection.getContentEncoding();
if (encoding != null && encoding.equalsIgnoreCase("base64")) {
respBytes = Base64.decode(new String(respBytes));
}
return respBytes;
}
示例2: main
import com.lowagie.text.pdf.codec.Base64; //导入依赖的package包/类
public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException {
final String key = "x3JJHMbDL1EzLkh9GBhXDw==";
final String combined = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
final byte[] sha1 = MessageDigest.getInstance("SHA-1").digest(combined.getBytes("UTF8"));
System.out.println("Number of bytes: " + sha1.length);
final String encoded = Base64.encodeBytes(sha1);
System.out.println("encoded string: " + encoded);
}
示例3: getTSAResponse
import com.lowagie.text.pdf.codec.Base64; //导入依赖的package包/类
/**
* Get timestamp token - communications layer
* @return - byte[] - TSA response, raw bytes (RFC 3161 encoded)
*/
protected byte[] getTSAResponse(byte[] requestBytes) throws Exception {
// Setup the TSA connection
URL url = new URL(tsaURL);
URLConnection tsaConnection;
tsaConnection = (URLConnection) url.openConnection();
tsaConnection.setDoInput(true);
tsaConnection.setDoOutput(true);
tsaConnection.setUseCaches(false);
tsaConnection.setRequestProperty("Content-Type", "application/timestamp-query");
//tsaConnection.setRequestProperty("Content-Transfer-Encoding", "base64");
tsaConnection.setRequestProperty("Content-Transfer-Encoding", "binary");
if ((tsaUsername != null) && !tsaUsername.equals("") ) {
String userPassword = tsaUsername + ":" + tsaPassword;
tsaConnection.setRequestProperty("Authorization", "Basic " +
new String(Base64.encodeBytes(userPassword.getBytes())));
}
OutputStream out = tsaConnection.getOutputStream();
out.write(requestBytes);
out.close();
// Get TSA response as a byte array
InputStream inp = tsaConnection.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = inp.read(buffer, 0, buffer.length)) >= 0) {
baos.write(buffer, 0, bytesRead);
}
byte[] respBytes = baos.toByteArray();
String encoding = tsaConnection.getContentEncoding();
if (encoding != null && encoding.equalsIgnoreCase("base64")) {
respBytes = Base64.decode(new String(respBytes));
}
return respBytes;
}
示例4: saveAndInsertIntoQueue
import com.lowagie.text.pdf.codec.Base64; //导入依赖的package包/类
private String saveAndInsertIntoQueue( FaxConfig faxConfig, FaxJob receivedFax, FaxJob faxFile ) {
String filename = receivedFax.getFile_name();
filename = filename.replace("|", "-");
if( filename.isEmpty() ) {
filename = System.currentTimeMillis() + ".pdf";
}
filename = filename.replace(".tif", ".pdf");
if( ! filename.endsWith(".pdf") || ! filename.endsWith(".PDF") ) {
filename = filename + ".pdf";
}
filename = filename.trim();
log.info("Saving the Fax file " + filename + " meta data to Oscar's eDoc system.");
EDoc newDoc = new EDoc("Recieved Fax", "Recieved Fax", filename, "",
DEFAULT_USER, DEFAULT_USER, "", 'A',
DateFormatUtils.format(receivedFax.getStamp(), "yyyy-MM-dd"),
"", "", "demographic", DEFAULT_USER, receivedFax.getNumPages() );
newDoc.setDocPublic("0");
filename = newDoc.getFileName();
log.info("Saving the Fax file " + filename + " to the local file system at " + DOCUMENT_DIR );
if( Base64.decodeToFile( faxFile.getDocument(), DOCUMENT_DIR + "/" + filename) ) {
newDoc.setContentType("application/pdf");
newDoc.setNumberOfPages(receivedFax.getNumPages());
String doc_no = EDocUtil.addDocumentSQL(newDoc);
Integer queueId = faxConfig.getQueue();
Integer docNum = Integer.parseInt(doc_no);
queueDocumentLinkDao.addActiveQueueDocumentLink(queueId, docNum);
log.debug( "Saved file " + filename + " to filesystem at " + DOCUMENT_DIR );
return filename;
}
log.debug( "Failed to save file " + filename + " to filesystem at " + DOCUMENT_DIR );
return null;
}