当前位置: 首页>>代码示例>>Java>>正文


Java ByteArrayOutputStream.close方法代码示例

本文整理汇总了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();
   }
}
 
开发者ID:mqsysadmin,项目名称:dpdirect,代码行数:25,代码来源:FileUtils.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ZipDecompressor.java

示例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;
}
 
开发者ID:hoangphuc3117,项目名称:Android-Crop-Receipt,代码行数:22,代码来源:Utils.java

示例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();
}
 
开发者ID:Javen205,项目名称:IJPay,代码行数:27,代码来源:SDKUtil.java

示例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();
}
 
开发者ID:Javen205,项目名称:IJPay,代码行数:32,代码来源:SDKUtil.java

示例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;
}
 
开发者ID:Lengchuan,项目名称:SpringBoot-Study,代码行数:24,代码来源:Base64.java

示例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;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:21,代码来源:BitmapUtil.java

示例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);// 返回读取字符串
}
 
开发者ID:longtaoge,项目名称:SelectName,代码行数:33,代码来源:FileOperate.java

示例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 "";
        }
    }
}
 
开发者ID:jiangkang,项目名称:KTools,代码行数:19,代码来源:SecurityUtils.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:JarFileSystem.java

示例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;
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:38,代码来源:RSAUtils.java

示例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();
    }
}
 
开发者ID:ghnor,项目名称:Flora,代码行数:32,代码来源:SingleActivity.java

示例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();
}
 
开发者ID:quanzhuo,项目名称:prada,代码行数:12,代码来源:StreamTool.java

示例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;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:38,代码来源:FileServiceImpl.java

示例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);
    }

}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:37,代码来源:XYTypeFilter.java


注:本文中的java.io.ByteArrayOutputStream.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。