本文整理汇总了Java中java.io.ByteArrayOutputStream.reset方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayOutputStream.reset方法的具体用法?Java ByteArrayOutputStream.reset怎么用?Java ByteArrayOutputStream.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.ByteArrayOutputStream
的用法示例。
在下文中一共展示了ByteArrayOutputStream.reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: usageString
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static String usageString(CommandLine commandLine, Ansi ansi) throws UnsupportedEncodingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
commandLine.usage(new PrintStream(baos, true, "UTF8"), ansi);
String result = baos.toString("UTF8");
if (ansi == Ansi.AUTO) {
baos.reset();
commandLine.usage(new PrintStream(baos, true, "UTF8"));
assertEquals(result, baos.toString("UTF8"));
} else if (ansi == Ansi.ON) {
baos.reset();
commandLine.usage(new PrintStream(baos, true, "UTF8"), Help.defaultColorScheme(Ansi.ON));
assertEquals(result, baos.toString("UTF8"));
}
return result;
}
示例2: compressQuality
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private void compressQuality(File outFile, long maxSize, int maxQuality) throws IOException {
long length = outFile.length();
int quality = 90;
if (length > maxSize) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BoxingLog.d("source file size : " + outFile.length() + ",path : " + outFile);
while (true) {
compressPhotoByQuality(outFile, bos, quality);
long size = bos.size();
BoxingLog.d("compressed file size : " + size);
if (quality <= maxQuality) {
break;
}
if (size < maxSize) {
break;
} else {
quality -= 10;
bos.reset();
}
}
OutputStream fos = new FileOutputStream(outFile);
bos.writeTo(fos);
bos.flush();
fos.close();
bos.close();
}
}
示例3: decrypt
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
@Override
public void decrypt(byte[] data, ByteArrayOutputStream stream) {
byte[] temp;
synchronized (decLock) {
stream.reset();
if (!_decryptIVSet) {
_decryptIVSet = true;
setIV(data, false);
temp = new byte[data.length - _ivLength];
System.arraycopy(data, _ivLength, temp, 0, data.length
- _ivLength);
} else {
temp = data;
}
_decrypt(temp, stream);
}
}
示例4: compressImage
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
* 质量压缩方法
*
* @param image
* @return
*/
public static Bitmap compressImage(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
int options = 100;
while (baos.toByteArray().length / 1024 > 100) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩
baos.reset();//重置baos即清空baos
//第一个参数 :图片格式 ,第二个参数: 图片质量,100为最高,0为最差 ,第三个参数:保存压缩后的数据的流
image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中
options -= 10;//每次都减少10
}
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片
return bitmap;
}
示例5: maybeAppendFragment
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
private static void maybeAppendFragment(ByteArrayOutputStream fragmentBuffer,
String charset,
StringBuilder result) {
if (fragmentBuffer.size() > 0) {
byte[] fragmentBytes = fragmentBuffer.toByteArray();
String fragment;
if (charset == null) {
fragment = new String(fragmentBytes, Charset.forName("UTF-8"));
} else {
try {
fragment = new String(fragmentBytes, charset);
} catch (UnsupportedEncodingException e) {
fragment = new String(fragmentBytes, Charset.forName("UTF-8"));
}
}
fragmentBuffer.reset();
result.append(fragment);
}
}
示例6: convertToDefiniteLength
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
* Just re-encode the outer layer of the PKCS#12 file to definite length encoding.
*
* @param berPKCS12File - original PKCS#12 file
* @return a byte array representing the DER encoding of the PFX structure
* @throws IOException
*/
public static byte[] convertToDefiniteLength(byte[] berPKCS12File)
throws IOException
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
Pfx pfx = Pfx.getInstance(berPKCS12File);
bOut.reset();
dOut.writeObject(pfx);
return bOut.toByteArray();
}
示例7: compressImage
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
* 压缩图片
*
* @param image
* @param size
* @param opt
* @return
*/
private static Bitmap compressImage(Bitmap image, int size, BitmapFactory.Options opt) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);// 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
int options = 100;
if (baos.toByteArray().length / 1024 <= size)
return image;
while (baos.toByteArray().length / 1024 > size && options > 0) { // 循环判断如果压缩后图片是否大于50kb,大于继续压缩
baos.reset();// 重置baos即清空baos
image.compress(getImgFormat(opt), options, baos);// 这里压缩比options=50,把压缩后的数据存放到baos中
if (options > 10)
options -= 10;// 每次都减少10
else
options -= 1;
}
ByteArrayInputStream isBm = new ByteArrayInputStream(
baos.toByteArray());// 把压缩后的数据baos存放到ByteArrayInputStream中
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);// 把ByteArrayInputStream数据生成图片
if(image!=null&&!image.isRecycled()) {
image.recycle();
image = null;
}
return bitmap;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例8: getQualifierSet
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
protected static final Set getQualifierSet(ASN1Sequence qualifiers)
throws CertPathValidatorException
{
Set pq = new HashSet();
if (qualifiers == null)
{
return pq;
}
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ASN1OutputStream aOut = new ASN1OutputStream(bOut);
Enumeration e = qualifiers.getObjects();
while (e.hasMoreElements())
{
try
{
aOut.writeObject((ASN1Encodable)e.nextElement());
pq.add(new PolicyQualifierInfo(bOut.toByteArray()));
}
catch (IOException ex)
{
throw new ExtCertPathValidatorException("Policy qualifier info cannot be decoded.", ex);
}
bOut.reset();
}
return pq;
}
示例9: getStaticSizeBitmapByteByBitmap
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
* 创建指定大小的bitmap的byte流,大小 <= maxSize
*
* @param srcBitmap bitmap
* @param maxSize kb,example 32kb
* @return byte流
*/
public static byte[] getStaticSizeBitmapByteByBitmap(Bitmap srcBitmap, int maxSize, Bitmap.CompressFormat format) {
// 首先进行一次大范围的压缩
Bitmap tempBitmap;
ByteArrayOutputStream output = new ByteArrayOutputStream();
// 设置矩阵数据
Matrix matrix = new Matrix();
srcBitmap.compress(format, 100, output);
// 如果进行了上面的压缩后,依旧大于32K,就进行小范围的微调压缩
byte[] bytes = output.toByteArray();
LogUtils.e(TAG, "压缩之前 = " + bytes.length);
while (bytes.length > maxSize) {
matrix.setScale(0.9f, 0.9f);//每次缩小 1/10
tempBitmap = srcBitmap;
srcBitmap = Bitmap.createBitmap(
tempBitmap, 0, 0,
tempBitmap.getWidth(), tempBitmap.getHeight(), matrix, true);
recyclerBitmaps(tempBitmap);
output.reset();
srcBitmap.compress(format, 100, output);
bytes = output.toByteArray();
LogUtils.e(TAG, "压缩一次 = " + bytes.length);
}
LogUtils.e(TAG, "压缩后的图片输出大小 = " + bytes.length);
recyclerBitmaps(srcBitmap);
return bytes;
}
示例10: compressByQuality
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
* 按质量压缩
*
* @param src 源图片
* @param maxByteSize 允许最大值字节数
* @param recycle 是否回收
* @return 质量压缩压缩过的图片
*/
public static Bitmap compressByQuality(Bitmap src, long maxByteSize, boolean recycle) {
if (isEmptyBitmap(src) || maxByteSize <= 0) return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int quality = 100;
src.compress(CompressFormat.JPEG, quality, baos);
while (baos.toByteArray().length > maxByteSize && quality > 0) {
baos.reset();
src.compress(CompressFormat.JPEG, quality -= 5, baos);
}
if (quality < 0) return null;
byte[] bytes = baos.toByteArray();
if (recycle && !src.isRecycled()) src.recycle();
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
示例11: unformatXMLString
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
public static void unformatXMLString(ByteArrayOutputStream arrayOutputStream) {
byte[] bytes = arrayOutputStream.toByteArray();
try(InputStream inputStream = new ByteArrayInputStream(bytes);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(inputStreamReader);){
arrayOutputStream.reset();
String line;
while ((line = reader.readLine()) != null){
arrayOutputStream.write((line.trim() + "\n").getBytes());
}
} catch (IOException e) {
logger.warn("Unable to remove formatting while saving UI XML string",e);
}
}
示例12: _mdx_decrypt
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
static byte[] _mdx_decrypt(byte[] comp_block) throws IOException{
ByteArrayOutputStream data = new ByteArrayOutputStream() ;
data.write(comp_block,4,4);
data.write(ripemd128.packIntLE(0x3695));
byte[] key = ripemd128.ripemd128(data.toByteArray());
data.reset();
data.write(comp_block,0,8);
byte[] comp_block2 = new byte[comp_block.length-8];
System.arraycopy(comp_block, 8, comp_block2, 0, comp_block.length-8);
data.write(_fast_decrypt(comp_block2, key));
return data.toByteArray();
}
示例13: setClasses
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
protected void setClasses(String jarPath) throws Exception {
ArrayList<String> names = new ArrayList(16);
ArrayList<byte[]> bytes = new ArrayList(16);
JarFile file = new JarFile(jarPath);
Enumeration<JarEntry> entries = file.entries();
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
int read = 0;
byte[] buffer = new byte[1024];
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
String nm = entry.getName();
nm = nm.substring(0, nm.lastIndexOf("."));
names.add(nm);
BufferedInputStream bis = new BufferedInputStream(file.getInputStream(entry));
while ((read = bis.read(buffer)) > -1) {
bos.write(buffer, 0, read);
}
bis.close();
bytes.add(bos.toByteArray());
bos.reset();
}
}
classNames = names.toArray(new String[0]);
classesBytes = bytes.toArray(new byte[0][]);
}
示例14: compressByQuality
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
* 按质量压缩
*
* @param src 源图片
* @param maxByteSize 允许最大值字节数
* @param recycle 是否回收
* @return 质量压缩压缩过的图片
*/
public static Bitmap compressByQuality(final Bitmap src, final long maxByteSize, final boolean recycle) {
if (isEmptyBitmap(src) || maxByteSize <= 0) return null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int quality = 100;
src.compress(CompressFormat.JPEG, quality, baos);
while (baos.toByteArray().length > maxByteSize && quality > 0) {
baos.reset();
src.compress(CompressFormat.JPEG, quality -= 5, baos);
}
if (quality < 0) return null;
byte[] bytes = baos.toByteArray();
if (recycle && !src.isRecycled()) src.recycle();
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
示例15: QualityCompressFromBitmap
import java.io.ByteArrayOutputStream; //导入方法依赖的package包/类
/**
* 质量压缩
* @param image
* @param targetSize 目标大小
* @return
*/
public static Bitmap QualityCompressFromBitmap(Bitmap image, int targetSize) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
int options = 100;
while (byteArrayOutputStream.toByteArray().length / 1024 > targetSize) { //循环判断如果压缩后图片是否大于targetSize,大于继续压缩
byteArrayOutputStream.reset();
//第一个参数 :图片格式 ,第二个参数: 图片质量,100为最高,0为最差 ,第三个参数:保存压缩后的数据的流
image.compress(Bitmap.CompressFormat.JPEG, options, byteArrayOutputStream);//这里压缩options%,把压缩后的数据存放到byteArrayOutputStream中
options -= 10;//每次都减少10
}
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());//把压缩后的数据存放到ByteArrayInputStream中
Bitmap bitmap = BitmapFactory.decodeStream(byteArrayInputStream, null, null);//把ByteArrayInputStream数据生成图片
return bitmap;
}