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


Java ByteArrayOutputStream.size方法代碼示例

本文整理匯總了Java中java.io.ByteArrayOutputStream.size方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayOutputStream.size方法的具體用法?Java ByteArrayOutputStream.size怎麽用?Java ByteArrayOutputStream.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.ByteArrayOutputStream的用法示例。


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

示例1: writeSection

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Write a section with header and data.
 * 
 * @param type
 *            the name of the section
 * @param data
 *            the data of the section
 * @param name
 *            the name, must be set if the id == 0
 * @throws IOException
 *             if any I/O error occur
 */
void writeSection( SectionType type, WasmOutputStream data, String name ) throws IOException {
    ByteArrayOutputStream baos = (ByteArrayOutputStream)data.out;
    int size = baos.size();
    if( size == 0 ) {
        return;
    }
    writeVaruint32( type.ordinal() );
    writeVaruint32( size );
    if( type == SectionType.Custom ) {
        byte[] bytes = name.getBytes( StandardCharsets.ISO_8859_1 );
        writeVaruint32( bytes.length );
        write( bytes );
    }
    baos.writeTo( this );
}
 
開發者ID:i-net-software,項目名稱:JWebAssembly,代碼行數:28,代碼來源:WasmOutputStream.java

示例2: 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 = Imgcodecs.imdecode(encoded, flags);
    encoded.release();

    return decoded;
}
 
開發者ID:johnhany,項目名稱:MOAAP,代碼行數:22,代碼來源:Utils.java

示例3: 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

示例4: getPartLength

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public long getPartLength() {
	long bodyLen = getBodyLength();
	if (bodyLen < 0) {
		return -1;
	}
	ByteArrayOutputStream overhead = new ByteArrayOutputStream();
	try {
		writeStart(overhead);
		writeDisposition(overhead);
		writeContentType(overhead);
		writeOtherHeaders(overhead);
		writeEndOfHeaders(overhead);
		writeEnd(overhead);

		return overhead.size() + bodyLen;
	} catch (IOException ex) {
		return -1;
	}
}
 
開發者ID:haducloc,項目名稱:appslandia-sweetsop,代碼行數:20,代碼來源:Part.java

示例5: getImageSize

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public static int getImageSize(Bitmap bmp) {
    if (bmp == null) {
        return 0;
    }
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bmp.compress(CompressFormat.PNG, 100, baos);
        int size = baos.size();
        baos.flush();
        baos.close();
        return size;
    } catch (IOException e) {
        e.printStackTrace();
        return 0;
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:LetvCacheTools.java

示例6: predictSubfulfillmentLength

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
static int predictSubfulfillmentLength(Fulfillment ff) {
    int fulfillmentLength = ff.getCondition().getMaxFulfillmentLength();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    OerOutputStream cos = new OerOutputStream(baos);
    try {
        cos.write16BitUInt(0 /* type Undefined */);
        byte[] bytes = new byte[fulfillmentLength];
        java.util.Arrays.fill( bytes, (byte) 0 );

        cos.writeOctetString(bytes);
        int result = baos.size();
        return result;
    }catch(Exception e) {
        throw new RuntimeException(e.toString(), e);
    } finally {
        cos.close();
    }
}
 
開發者ID:mgrand,項目名稱:bigchaindb-java-driver,代碼行數:19,代碼來源:ThresholdSHA256Fulfillment.java

示例7: determineSize

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
private int determineSize(Serializable ser) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(ser);
    oos.close();
    return baos.size();
}
 
開發者ID:Aptoide,項目名稱:AppCoins-ethereumj,代碼行數:8,代碼來源:RLPTest.java

示例8: convert

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Converts a byte array from a source base to a target base using the alphabet.
 */
private byte[] convert(final byte[] message, final int sourceBase, final int targetBase) {
    /**
     * This algorithm is inspired by: http://codegolf.stackexchange.com/a/21672
     */

    final int estimatedLength = estimateOutputLength(message.length, sourceBase, targetBase);

    final ByteArrayOutputStream out = new ByteArrayOutputStream(estimatedLength);

    byte[] source = message;

    while (source.length > 0) {
        final ByteArrayOutputStream quotient = new ByteArrayOutputStream(source.length);

        int remainder = 0;

        for (int i = 0; i < source.length; i++) {
            final int accumulator = (source[i] & 0xFF) + remainder * sourceBase;
            final int digit = (accumulator - (accumulator % targetBase)) / targetBase;

            remainder = accumulator % targetBase;

            if (quotient.size() > 0 || digit > 0) {
                quotient.write(digit);
            }
        }

        out.write(remainder);

        source = quotient.toByteArray();
    }

    // pad output with zeroes corresponding to the number of leading zeroes in the message
    for (int i = 0; i < message.length - 1 && message[i] == 0; i++) {
        out.write(0);
    }

    return reverse(out.toByteArray());
}
 
開發者ID:seruco,項目名稱:base62,代碼行數:43,代碼來源:Base62.java

示例9: getBytesFromInputStream

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public static byte[] getBytesFromInputStream(InputStream is, int maxSize) throws IOException {
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	byte[] buffer = new byte[0xFFFF];

	for (int len; (len = is.read(buffer)) != -1 && os.size() < maxSize; ) {
		os.write(buffer, 0, len);
	}

	if (os.size() >= maxSize) {
		throw new IOException("File was too big");
	}

	os.flush();
	return os.toByteArray();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:PubkeyListActivity.java

示例10: readString

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Read a string from the binary model (System default should be UTF-8)
 * @param ds input data stream
 * @return a String from the model
 */
public static String readString(DataInputStream ds) throws IOException {
    ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
    while (true) {
        byte byteValue = ds.readByte();
        if ((byteValue != 32) && (byteValue != 10)) {
            byteBuffer.write(byteValue);
        } else if (byteBuffer.size() > 0) {
            break;
        }
    }
    String word = byteBuffer.toString();
    byteBuffer.close();
    return word;
}
 
開發者ID:uhh-lt,項目名稱:LT-ABSA,代碼行數:20,代碼來源:W2vSpace.java

示例11: connect

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
@WorkerThread
public void connect(byte[] infoHash, byte[] peerId) throws IOException, InvalidKeyException, InterruptedException {
    if (ValidationUtils.isEmptyArray(infoHash) || ValidationUtils.isEmptyArray(peerId)) {
        return;
    }

    if (mConnection.connect() == false) {
        if (DEBUG) {
            Log.e(TAG, "Connect to peer failed");
        }
        return;
    }

    final ByteArrayOutputStream receivedBytes = new ByteArrayOutputStream();
    final CountDownLatch latch = new CountDownLatch(1);
    Connection.ConnectionListener listener = new Connection.ConnectionListener() {
        @Override
        public void onReceived(@NonNull byte[] received) {
            try {
                receivedBytes.write(received);
            } catch (IOException ignore) {

            } finally {
                if (receivedBytes.size() >= HandshakeMessage.BASE_HANDSHAKE_LENGTH) {
                    latch.countDown();
                }
            }
        }
    };

    // hand shake
    mConnection.addConnectionListener(listener);
    try {
        HandshakeMessage handshake = new HandshakeMessage(infoHash, peerId);
        requestSendProtocolMessage(handshake);
        latch.await(1, TimeUnit.MINUTES);

        // validate handshake
        HandshakeMessage response = HandshakeMessage.parseFromResponse(ByteBuffer.wrap(receivedBytes.toByteArray()));
        if (response == null || handshake.validateHandShake(response) == false) {
            if (DEBUG) {
                Log.e(TAG, "connect(), Failed to handshake");
            }
            return;
        }

        if (DEBUG) {
            Log.i(TAG, "Hand shake finished ");
        }
        mConnection.addConnectionListener(mConnectionListener);
    } finally {
        mConnection.removeListener(listener);
    }
}
 
開發者ID:forusoul70,項目名稱:playTorrent,代碼行數:55,代碼來源:Peer.java

示例12: size

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * The count of bytes in the stream. Work only for in memory stream.
 * 
 * @return the data size
 */
int size() {
    ByteArrayOutputStream baos = (ByteArrayOutputStream)out;
    return baos.size();
}
 
開發者ID:i-net-software,項目名稱:JWebAssembly,代碼行數:10,代碼來源:WasmOutputStream.java


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