本文整理匯總了Java中java.io.ByteArrayOutputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayOutputStream.close方法的具體用法?Java ByteArrayOutputStream.close怎麽用?Java ByteArrayOutputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.ByteArrayOutputStream
的用法示例。
在下文中一共展示了ByteArrayOutputStream.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readInputStreamBytes
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
* Reads the byte content of an <code>InputStream</code>.
*
* @param inputStream the <code>InputStream</code> from which to read content.
*
* @return the byte content of the <code>InputStream</code>.
*
* @exception IOException if there is an error reading the <code>InputStream</code>.
*/
public static byte[] readInputStreamBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[4096];
int bytesRead = inputStream.read(buffer);
while (bytesRead != -1) {
outputStream.write(buffer, 0, bytesRead);
bytesRead = inputStream.read(buffer);
}
return outputStream.toByteArray();
}
finally {
outputStream.close();
}
}
示例2: decompress
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
static byte[] decompress(byte[] bytesIn, int offset) throws Exception {
Inflater inflater = new Inflater();
inflater.setInput(bytesIn, offset, bytesIn.length - offset);
ByteArrayOutputStream stream = new ByteArrayOutputStream(bytesIn.length - offset);
byte[] buffer = new byte[1024];
while (!inflater.finished()) {
int count = inflater.inflate(buffer);
stream.write(buffer, 0, count);
}
stream.close();
byte[] bytesOut = stream.toByteArray();
inflater.end();
return bytesOut;
}
示例3: loadResource
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public static Mat loadResource(Context context, int resourceId, int flags) throws IOException
{
InputStream is = context.getResources().openRawResource(resourceId);
ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
Mat encoded = new Mat(1, os.size(), CvType.CV_8U);
encoded.put(0, 0, os.toByteArray());
os.close();
Mat decoded = Highgui.imdecode(encoded, flags);
encoded.release();
return decoded;
}
示例4: deflater
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
* 壓縮.
*
* @param inputByte
* 需要解壓縮的byte[]數組
* @return 壓縮後的數據
* @throws IOException
*/
public static byte[] deflater(final byte[] inputByte) throws IOException {
int compressedDataLength = 0;
Deflater compresser = new Deflater();
compresser.setInput(inputByte);
compresser.finish();
ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
byte[] result = new byte[1024];
try {
while (!compresser.finished()) {
compressedDataLength = compresser.deflate(result);
o.write(result, 0, compressedDataLength);
}
} finally {
o.close();
}
compresser.end();
return o.toByteArray();
}
示例5: inflater
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
* 解壓縮.
*
* @param inputByte
* byte[]數組類型的數據
* @return 解壓縮後的數據
* @throws IOException
*/
public static byte[] inflater(final byte[] inputByte) throws IOException {
int compressedDataLength = 0;
Inflater compresser = new Inflater(false);
compresser.setInput(inputByte, 0, inputByte.length);
ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
byte[] result = new byte[1024];
try {
while (!compresser.finished()) {
compressedDataLength = compresser.inflate(result);
if (compressedDataLength == 0) {
break;
}
o.write(result, 0, compressedDataLength);
}
} catch (Exception ex) {
System.err.println("Data format error!\n");
ex.printStackTrace();
} finally {
o.close();
}
compresser.end();
return o.toByteArray();
}
示例6: decode
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
* 解密
*
* @param s
* @return
*/
public static byte[] decode(String s) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
decode(s, bos);
} catch (IOException e) {
throw new RuntimeException();
}
byte[] decodedBytes = bos.toByteArray();
try {
bos.close();
bos = null;
} catch (IOException ex) {
System.err.println("Error while decoding BASE64: " + ex.toString());
}
return decodedBytes;
}
示例7: createFromNV21
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public static byte[] createFromNV21(@NonNull final byte[] data,
final int width,
final int height,
int rotation,
final Rect croppingRect,
final boolean flipHorizontal)
throws IOException
{
byte[] rotated = rotateNV21(data, width, height, rotation, flipHorizontal);
final int rotatedWidth = rotation % 180 > 0 ? height : width;
final int rotatedHeight = rotation % 180 > 0 ? width : height;
YuvImage previewImage = new YuvImage(rotated, ImageFormat.NV21,
rotatedWidth, rotatedHeight, null);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
previewImage.compressToJpeg(croppingRect, 80, outputStream);
byte[] bytes = outputStream.toByteArray();
outputStream.close();
return bytes;
}
示例8: readFromAsset
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
* 描述: 從SDCard讀取文件</br>
* 開發人員:chixin</br>
* 創建時間:2015-4-17</br>
*
* @param fileName
* @return
* @throws Exception
*/
public String readFromAsset(String fileName) throws Exception {
String path = "offLineData/" + fileName;
// 創建文件輸入流對象
InputStream inStream = context.getResources().getAssets().open(path);
// 構建將轉換輸出流對象
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
// 定義一個字節緩存數組
byte[] buffer = new byte[4096];
// 讀取的數據長度
int len = 0;
// 循環讀取內容
while ((len = inStream.read(buffer)) != -1) {
// 將讀取的內容寫入流當中
outStream.write(buffer, 0, len);
}
// 將讀取的數據轉換為字節數組
byte[] datas = outStream.toByteArray();
// 關閉輸入流和輸出流對象
outStream.close();
inStream.close();
return new String(datas);// 返回讀取字符串
}
示例9: bmp2base64
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public static String bmp2base64(Bitmap bitmap, Bitmap.CompressFormat compressFormat,int quality){
if (bitmap == null){
return "";
}else {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(compressFormat,quality,outputStream);
try {
outputStream.flush();
outputStream.close();
byte[] bytes = outputStream.toByteArray();
return Base64.encodeToString(bytes,Base64.DEFAULT);
} catch (IOException e) {
return "";
}
}
}
示例10: getMemInputStream
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
private InputStream getMemInputStream(JarFile jf, JarEntry je)
throws IOException {
InputStream is = getInputStream4336753(jf, je);
ByteArrayOutputStream os = new ByteArrayOutputStream(is.available());
try {
FileUtil.copy(is, os);
} finally {
os.close();
}
return new ByteArrayInputStream(os.toByteArray());
}
示例11: decryptByPublicKey
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
* <p>
* 公鑰解密
* </p>
*
* @param encryptedData 已加密數據
* @param publicKey 公鑰(BASE64編碼)
* @return
* @throws Exception
*/
public static byte[] decryptByPublicKey(byte[] encryptedData, String publicKey) throws Exception {
byte[] keyBytes = DigestUtils.getdeBASE64inCodec(publicKey);
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
Key publicK = keyFactory.generatePublic(x509KeySpec);
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
cipher.init(Cipher.DECRYPT_MODE, publicK);
int inputLen = encryptedData.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 對數據分段解密
while (inputLen - offSet > 0) {
if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK);
} else {
cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * MAX_DECRYPT_BLOCK;
}
byte[] decryptedData = out.toByteArray();
out.close();
return decryptedData;
}
示例12: testBytes
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
private void testBytes() {
try {
final InputStream is = getResources().getAssets().open("test4.jpg");
long fileSize = is.available();
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int len = -1;
while ((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
os.close();
is.close();
byte[] bitmapBytes = os.toByteArray();
Bitmap originBitmap = BitmapFactory.decodeByteArray(bitmapBytes, 0, bitmapBytes.length);
setupSourceInfo(originBitmap, fileSize);
Flora.with(TAG).load(bitmapBytes).compress(new Callback<String>() {
@Override
public void callback(String s) {
File file = new File(s);
setupResultInfo(s, file.length());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: readStream
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public static byte[] readStream(InputStream inStream) throws Exception{
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while( (len=inStream.read(buffer)) != -1){
outSteam.write(buffer, 0, len);
}
outSteam.close();
inStream.close();
return outSteam.toByteArray();
}
示例14: handleAggregatePDFFiles
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
@Override
protected FilePDFVO handleAggregatePDFFiles(AuthenticationVO auth, FileModule module, Long id, String logicalPath, Boolean active, PSFVO psf) throws Exception {
checkFileModuleId(module, id);
FileDao fileDao = this.getFileDao();
Timestamp now = new Timestamp(System.currentTimeMillis());
User user = CoreUtil.getUser();
Collection files = fileDao.findFiles(module, id, logicalPath, active, null, CoreUtil.PDF_MIMETYPE_STRING, psf);
PDFMerger merger = new PDFMerger(fileDao);
merger.setFiles(files);
fileDao.toFileOutVOCollection(files);
FilePDFVO pdfVO = new FilePDFVO();
pdfVO.setContentTimestamp(now);
pdfVO.setRequestingUser(this.getUserDao().toUserOutVO(user));
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
merger.save(stream);
} finally {
stream.close();
}
byte[] documentData = stream.toByteArray();
pdfVO.setContentType(CoreUtil.getPDFMimeType());
pdfVO.setFiles(files);
StringBuilder fileName = new StringBuilder(PDFMerger.AGGREGATED_PDF_FILES_FILENAME_PREFIX);
fileName.append(module.getValue());
fileName.append("_");
fileName.append(id);
fileName.append("_");
fileName.append(CommonUtil.formatDate(now, CommonUtil.DIGITS_ONLY_DATETIME_PATTERN));
fileName.append(".");
fileName.append(CoreUtil.PDF_FILENAME_EXTENSION);
pdfVO.setFileName(fileName.toString());
pdfVO.setMd5(CommonUtil.getHex(MessageDigest.getInstance("MD5").digest(documentData)));
pdfVO.setSize(documentData.length);
addAggregatedPDFFilesExportedJournalEntry(module, id, pdfVO, now, user);
pdfVO.setDocumentDatas(documentData);
return pdfVO;
}
示例15: doSaveMultiSelection
import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
synchronized public void doSaveMultiSelection() {
if (selectionList == null) {
log.warning("no profile to save");
return;
}
try {
int xValue[] = new int[selectionList.size()];
int yValue[] = new int[selectionList.size()];
int widthValue[] = new int[selectionList.size()];
int heightValue[] = new int[selectionList.size()];
Iterator iterator = selectionList.iterator();
int j = 0;
while (iterator.hasNext()) {
SelectionRectangle tmpRect = (SelectionRectangle) iterator.next();
xValue[j] = tmpRect.x;
yValue[j] = tmpRect.y;
widthValue[j] = tmpRect.width;
heightValue[j] = tmpRect.height;
j++;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(xValue);
oos.writeObject(yValue);
oos.writeObject(widthValue);
oos.writeObject(heightValue);
prefs().putByteArray("XYTypeFilter.multiSelection", bos.toByteArray());
oos.close();
bos.close();
log.info("multi selection saveed to preferences");
} catch (Exception e) {
log.warning("couldn't save profile: " + e);
}
}