當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteArrayOutputStream.reset方法代碼示例

本文整理匯總了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;
}
 
開發者ID:remkop,項目名稱:picocli,代碼行數:17,代碼來源:HelpTestUtil.java

示例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();
    }
}
 
開發者ID:Bilibili,項目名稱:boxing,代碼行數:28,代碼來源:ImageCompressor.java

示例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);
	}
}
 
開發者ID:breakEval13,項目名稱:NSS,代碼行數:19,代碼來源:CryptBase.java

示例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;
}
 
開發者ID:Liuzhiyang94,項目名稱:ComponentProjectDemo,代碼行數:22,代碼來源:CommonUtils.java

示例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);
  }
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:20,代碼來源:VCardResultParser.java

示例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();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:22,代碼來源:PKCS12Util.java

示例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;
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:39,代碼來源:CompressImage.java

示例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;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:34,代碼來源:CertPathValidatorUtilities.java

示例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;
}
 
開發者ID:chendongMarch,項目名稱:SocialSdkLibrary,代碼行數:34,代碼來源:BitmapUtils.java

示例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);
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:23,代碼來源:ImageUtils.java

示例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);
	}
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:15,代碼來源:XMLUtil.java

示例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();
  }
 
開發者ID:KnIfER,項目名稱:mdict-parser-java,代碼行數:13,代碼來源:mdictRes.java

示例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][]);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:InstrumentationTest.java

示例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);
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:23,代碼來源:ImageUtils.java

示例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;
}
 
開發者ID:AnliaLee,項目名稱:PhotoFactory,代碼行數:21,代碼來源:CompressUtils.java


注:本文中的java.io.ByteArrayOutputStream.reset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。