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


Java Base64OutputStream類代碼示例

本文整理匯總了Java中android.util.Base64OutputStream的典型用法代碼示例。如果您正苦於以下問題:Java Base64OutputStream類的具體用法?Java Base64OutputStream怎麽用?Java Base64OutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Base64OutputStream類屬於android.util包,在下文中一共展示了Base64OutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import android.util.Base64OutputStream; //導入依賴的package包/類
@Override
public void run() {
  if (!mIsRunning || mBitmap == null) {
    return;
  }
  int width = mBitmap.getWidth();
  int height = mBitmap.getHeight();
  mStream.reset();
  Base64OutputStream base64Stream = new Base64OutputStream(mStream, Base64.DEFAULT);
  // request format is either "jpeg" or "png"
  Bitmap.CompressFormat format = Bitmap.CompressFormat.valueOf(mRequest.format.toUpperCase());
  mBitmap.compress(format, mRequest.quality, base64Stream);
  mEvent.data = mStream.toString();
  mMetadata.pageScaleFactor = 1;
  mMetadata.deviceWidth = width;
  mMetadata.deviceHeight = height;
  mEvent.metadata = mMetadata;
  mPeer.invokeMethod("Page.screencastFrame", mEvent, null);
  mMainHandler.postDelayed(mEndAction, FRAME_DELAY);
}
 
開發者ID:Laisly,項目名稱:weex,代碼行數:21,代碼來源:ScreencastDispatcher.java

示例2: encodeObject

import android.util.Base64OutputStream; //導入依賴的package包/類
public static String encodeObject(Serializable serializable) {
    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutput;
    try {
        objectOutput = new ObjectOutputStream(arrayOutputStream);
        objectOutput.writeObject(serializable);
        byte[] data = arrayOutputStream.toByteArray();
        objectOutput.close();

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Base64OutputStream b64 = new Base64OutputStream(out, android.util.Base64.DEFAULT);
        b64.write(data);
        b64.close();
        return new String(out.toByteArray());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:mattstraehl,項目名稱:AmgiNori,代碼行數:20,代碼來源:Base64.java

示例3: getStringFile

import android.util.Base64OutputStream; //導入依賴的package包/類
public static String getStringFile(File f) {
    InputStream inputStream = null;
    String encodedFile = "", lastVal;
    try {
        inputStream = new FileInputStream(f.getAbsolutePath());

        byte[] buffer = new byte[10240];//specify the size to allow
        int bytesRead;
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        Base64OutputStream output64 = new Base64OutputStream(output, Base64.DEFAULT);

        while ((bytesRead = inputStream.read(buffer)) != -1) {
            output64.write(buffer, 0, bytesRead);
        }
        output64.close();
        encodedFile = output.toString();
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    lastVal = encodedFile;
    return lastVal;
}
 
開發者ID:active-citizen,項目名稱:android.java,代碼行數:25,代碼來源:FileUtils.java

示例4: toStringByteArray

import android.util.Base64OutputStream; //導入依賴的package包/類
/**
 * Converts an object to their string byte array representation.
 *
 * @param object an object
 * @return the {@code string} byte array representation of the object
 */
@Nullable
public static String toStringByteArray(Object object) {
  ObjectOutputStream objectOutput;
  ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
  try {
    objectOutput = new ObjectOutputStream(arrayOutputStream);
    objectOutput.writeObject(object);
    byte[] data = arrayOutputStream.toByteArray();
    objectOutput.close();
    arrayOutputStream.close();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Base64OutputStream b64 = new Base64OutputStream(out, Base64.DEFAULT);
    b64.write(data);
    b64.close();
    out.close();
    return new String(out.toByteArray());
  } catch (IOException e) {
    e.printStackTrace();
  }
  return null;
}
 
開發者ID:IDme,項目名稱:ID.me-WebVerify-SDK-Android,代碼行數:29,代碼來源:ObjectHelper.java

示例5: toBase64

import android.util.Base64OutputStream; //導入依賴的package包/類
public String toBase64() {
    ObjectOutputStream os = null;
    try {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        Base64OutputStream enc = new Base64OutputStream(buf, Base64.NO_WRAP);
        os = new ObjectOutputStream(enc);

        PGP.serialize(mPair, os);

        os.close();
        return buf.toString();
    }
    catch (Exception e) {
        // shouldn't happen - crash
        throw new RuntimeException(e);
    }
    finally {
        try {
            if (os != null)
                os.close();
        }
        catch (IOException ignored) {
        }
    }
}
 
開發者ID:kontalk,項目名稱:androidclient,代碼行數:26,代碼來源:PersonalKey.java

示例6: objectToString

import android.util.Base64OutputStream; //導入依賴的package包/類
public static String objectToString(Serializable object) {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	try {
		new ObjectOutputStream(out).writeObject(object);
		byte[] data = out.toByteArray();
		out.close();

		out = new ByteArrayOutputStream();
		Base64OutputStream b64 = new Base64OutputStream(out, Base64.DEFAULT);
		b64.write(data);
		b64.close();
		out.close();

		return new String(out.toByteArray());
	} catch (IOException e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:Inego,項目名稱:Aglona-Reader-Android,代碼行數:20,代碼來源:MainActivity.java

示例7: fileToBase64

import android.util.Base64OutputStream; //導入依賴的package包/類
/**
 * 
 * @param file
 * @return
 */
public static String fileToBase64(String file) {
    String result= null;
    try {
        FileInputStream fis = new FileInputStream(new File(file));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Base64OutputStream base64out = new Base64OutputStream(baos, Base64.NO_WRAP);
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = fis.read(buffer)) >= 0) {
            base64out.write(buffer, 0, len);
        }
        base64out.flush();
        base64out.close();
        /*
         * Why should we close Base64OutputStream before processing the data:
         * http://stackoverflow.com/questions/24798745/android-file-to-base64-using-streaming-sometimes-missed-2-bytes
         */
        result = new String(baos.toByteArray(), "UTF-8");
        baos.close();
        fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
開發者ID:RincLiu,項目名稱:Roid-Library,代碼行數:31,代碼來源:RLFileUtil.java

示例8: writeToFromStream

import android.util.Base64OutputStream; //導入依賴的package包/類
private void writeToFromStream(OutputStream os, StreamWrapper entry)
        throws IOException {

    // Send the meta data.
    writeMetaData(os, entry.name, entry.contentType);

    int bytesRead;

    // Upload the file's contents in Base64.
    Base64OutputStream bos = new Base64OutputStream(os, Base64.NO_CLOSE | Base64.NO_WRAP);

    // Read from input stream until no more data's left to read.
    while ((bytesRead = entry.inputStream.read(buffer)) != -1) {
        bos.write(buffer, 0, bytesRead);
    }

    // Close the Base64 output stream.
    if (bos != null) {
        bos.close();
    }

    // End the meta data.
    endMetaData(os);

    // Close input stream.
    if (entry.autoClose) {
        // Safely close the input stream.
        if (entry.inputStream != null) {
            entry.inputStream.close();
        }
    }
}
 
開發者ID:HujiangTechnology,項目名稱:RestVolley,代碼行數:33,代碼來源:JsonStreamerEntity.java

示例9: writeToFromFile

import android.util.Base64OutputStream; //導入依賴的package包/類
private void writeToFromFile(OutputStream os, FileWrapper wrapper)
        throws IOException {

    // Send the meta data.
    writeMetaData(os, wrapper.file.getName(), wrapper.contentType);

    int bytesRead;

    // Open the file for reading.
    FileInputStream in = new FileInputStream(wrapper.file);

    // Upload the file's contents in Base64.
    Base64OutputStream bos = new Base64OutputStream(os, Base64.NO_CLOSE | Base64.NO_WRAP);

    // Read from file until no more data's left to read.
    while ((bytesRead = in.read(buffer)) != -1) {
        bos.write(buffer, 0, bytesRead);
    }

    // Close the Base64 output stream.
    if (bos != null) {
        bos.close();
    }

    // End the meta data.
    endMetaData(os);

    // Safely close the input stream.
    if (in != null) {
        in.close();
    }
}
 
開發者ID:HujiangTechnology,項目名稱:RestVolley,代碼行數:33,代碼來源:JsonStreamerEntity.java

示例10: openResponseBodyFile

import android.util.Base64OutputStream; //導入依賴的package包/類
public OutputStream openResponseBodyFile(String requestId, boolean base64Encode)
    throws IOException {
  OutputStream out = mContext.openFileOutput(getFilename(requestId), Context.MODE_PRIVATE);
  out.write(base64Encode ? 1 : 0);
  if (base64Encode) {
    return new Base64OutputStream(out, Base64.DEFAULT);
  } else {
    return out;
  }
}
 
開發者ID:misakuo,項目名稱:Dream-Catcher,代碼行數:11,代碼來源:ResponseBodyFileManager.java

示例11: writeBitmapJSON

import android.util.Base64OutputStream; //導入依賴的package包/類
public synchronized void writeBitmapJSON(Bitmap.CompressFormat format, int quality,
                                         OutputStream out)
        throws IOException {
    if (null == mCached || mCached.getWidth() == 0 || mCached.getHeight() == 0) {
        out.write("null".getBytes());
    } else {
        out.write('"');
        final Base64OutputStream imageOut = new Base64OutputStream(out, Base64.NO_WRAP);
        mCached.compress(Bitmap.CompressFormat.PNG, 100, imageOut);
        imageOut.flush();
        out.write('"');
    }
}
 
開發者ID:sensorsdata,項目名稱:sa-sdk-android,代碼行數:14,代碼來源:ViewSnapshot.java

示例12: getBase64Param

import android.util.Base64OutputStream; //導入依賴的package包/類
public static String getBase64Param(File f) throws Exception {
  FileInputStream in = new FileInputStream(f.getAbsoluteFile());
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Base64OutputStream output64 = new Base64OutputStream(out, Base64.DEFAULT);
  byte[] b = new byte[8192];
  int n;
  while ((n = in.read(b)) != -1) {
    output64.write(b, 0, n);
  }
  output64.close();
  in.close();
  return out.toString();
}
 
開發者ID:fancysherry,項目名稱:shr,代碼行數:14,代碼來源:NetUtil.java

示例13: getPepAvatar

import android.util.Base64OutputStream; //導入依賴的package包/類
private Avatar getPepAvatar(Bitmap bitmap, Bitmap.CompressFormat format, int quality) {
    try {
        ByteArrayOutputStream mByteArrayOutputStream = new ByteArrayOutputStream();
        Base64OutputStream mBase64OutputStream = new Base64OutputStream(mByteArrayOutputStream, Base64.DEFAULT);
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        DigestOutputStream mDigestOutputStream = new DigestOutputStream(mBase64OutputStream, digest);
        if (!bitmap.compress(format, quality, mDigestOutputStream)) {
            return null;
        }
        mDigestOutputStream.flush();
        mDigestOutputStream.close();
        long chars = mByteArrayOutputStream.size();
        if (format != Bitmap.CompressFormat.PNG && quality >= 50 && chars >= Config.AVATAR_CHAR_LIMIT) {
            int q = quality - 2;
            Log.d(Config.LOGTAG, "avatar char length was " + chars + " reducing quality to " + q);
            return getPepAvatar(bitmap, format, q);
        }
        Log.d(Config.LOGTAG, "settled on char length " + chars + " with quality=" + quality);
        final Avatar avatar = new Avatar();
        avatar.sha1sum = CryptoHelper.bytesToHex(digest.digest());
        avatar.image = new String(mByteArrayOutputStream.toByteArray());
        if (format.equals(Bitmap.CompressFormat.WEBP)) {
            avatar.type = "image/webp";
        } else if (format.equals(Bitmap.CompressFormat.JPEG)) {
            avatar.type = "image/jpeg";
        } else if (format.equals(Bitmap.CompressFormat.PNG)) {
            avatar.type = "image/png";
        }
        avatar.width = bitmap.getWidth();
        avatar.height = bitmap.getHeight();
        return avatar;
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:kriztan,項目名稱:Pix-Art-Messenger,代碼行數:36,代碼來源:FileBackend.java

示例14: writeBitmapJSON

import android.util.Base64OutputStream; //導入依賴的package包/類
public synchronized void writeBitmapJSON(Bitmap.CompressFormat format, int quality, OutputStream out)
    throws IOException {
    if (null == mCached || mCached.getWidth() == 0 || mCached.getHeight() == 0) {
        out.write("null".getBytes());
    } else {
        out.write('"');
        final Base64OutputStream imageOut = new Base64OutputStream(out, Base64.NO_WRAP);
        mCached.compress(Bitmap.CompressFormat.PNG, 100, imageOut);
        imageOut.flush();
        out.write('"');
    }
}
 
開發者ID:perludem,項目名稱:DPR-KITA,代碼行數:13,代碼來源:ViewSnapshot.java

示例15: getPepAvatar

import android.util.Base64OutputStream; //導入依賴的package包/類
private Avatar getPepAvatar(Bitmap bitmap, Bitmap.CompressFormat format, int quality) {
	try {
		ByteArrayOutputStream mByteArrayOutputStream = new ByteArrayOutputStream();
		Base64OutputStream mBase64OutputStream = new Base64OutputStream(mByteArrayOutputStream, Base64.DEFAULT);
		MessageDigest digest = MessageDigest.getInstance("SHA-1");
		DigestOutputStream mDigestOutputStream = new DigestOutputStream(mBase64OutputStream, digest);
		if (!bitmap.compress(format, quality, mDigestOutputStream)) {
			return null;
		}
		mDigestOutputStream.flush();
		mDigestOutputStream.close();
		long chars = mByteArrayOutputStream.size();
		if (format != Bitmap.CompressFormat.PNG && quality >= 50 && chars >= Config.AVATAR_CHAR_LIMIT) {
			int q = quality - 2;
			Log.d(Config.LOGTAG, "avatar char length was " + chars + " reducing quality to " + q);
			return getPepAvatar(bitmap, format, q);
		}
		Log.d(Config.LOGTAG, "settled on char length " + chars + " with quality=" + quality);
		final Avatar avatar = new Avatar();
		avatar.sha1sum = CryptoHelper.bytesToHex(digest.digest());
		avatar.image = new String(mByteArrayOutputStream.toByteArray());
		if (format.equals(Bitmap.CompressFormat.WEBP)) {
			avatar.type = "image/webp";
		} else if (format.equals(Bitmap.CompressFormat.JPEG)) {
			avatar.type = "image/jpeg";
		} else if (format.equals(Bitmap.CompressFormat.PNG)) {
			avatar.type = "image/png";
		}
		avatar.width = bitmap.getWidth();
		avatar.height = bitmap.getHeight();
		return avatar;
	} catch (Exception e) {
		return null;
	}
}
 
開發者ID:siacs,項目名稱:Conversations,代碼行數:36,代碼來源:FileBackend.java


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