当前位置: 首页>>代码示例>>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;未经允许,请勿转载。