Use is subject to License Terms. Your use of this web site or any of its contents or software indicates your agreement to be bound by these License Terms.
Copyright © 2006 Sun Microsystems, Inc. and Motorola, Inc. All rights reserved.
Overview Package Class Use Tree Deprecated Index Help
MID Profile
PREV CLASS NEXT CLASS FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
java.io
Class ByteArrayOutputStream
java.lang.Object
extended byjava.io.OutputStream
extended byjava.io.ByteArrayOutputStream
public class ByteArrayOutputStream
extends OutputStream
This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is written to it. The data can be retrieved using toByteArray() and toString().
Since:
JDK1.0, CLDC 1.0
Field Summary
protected byte[] buf
The buffer where data is stored.
protected int count
The number of valid bytes in the buffer.
Constructor Summary
ByteArrayOutputStream()
Creates a new byte array output stream.
ByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
Method Summary
void close()
Closes this output stream and releases any system resources associated with this stream.
void reset()
Resets the count field of this byte array output stream to zero, so that all currently accumulated output in the output stream is discarded.
int size()
Returns the current size of the buffer.
byte[] toByteArray()
Creates a newly allocated byte array.
String toString()
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding.
void write(byte[] b, int off, int len)
Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
void write(int b)
Writes the specified byte to this byte array output stream.
Methods inherited from class java.io.OutputStream
flush, write
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Field Detail
buf
protected byte[] buf
The buffer where data is stored.
count
protected int count
The number of valid bytes in the buffer.
Constructor Detail
ByteArrayOutputStream
public ByteArrayOutputStream()
Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if necessary.
ByteArrayOutputStream
public ByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
Parameters:
size - the initial size.
Throws:
IllegalArgumentException - if size is negative.
Method Detail
write
public void write(int b)
Writes the specified byte to this byte array output stream.
Specified by:
write in class OutputStream
Parameters:
b - the byte to be written.
write
public void write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
Overrides:
write in class OutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
reset
public void reset()
Resets the count field of this byte array output stream to zero, so that all currently accumulated output in the output stream is discarded. The output stream can be used again, reusing the already allocated buffer space.
See Also:
ByteArrayInputStream.count
toByteArray
public byte[] toByteArray()
Creates a newly allocated byte array. Its size is the current size of this output stream and the valid contents of the buffer have been copied into it.
Returns:
the current contents of this output stream, as a byte array.
See Also:
size()
size
public int size()
Returns the current size of the buffer.
Returns:
the value of the count field, which is the number of valid bytes in this output stream.
See Also:
count
toString
public String toString()
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding.
Overrides:
toString in class Object
Returns:
String translated from the buffer's contents.
Since:
JDK1.1
close
public void close()
throws IOException
Closes this output stream and releases any system resources associated with this stream. A closed stream cannot perform output operations and cannot be reopened.
Overrides:
close in class OutputStream
Throws:
IOException - if an I/O error occurs.
Overview Package Class Use Tree Deprecated Index Help
MID Profile
PREV CLASS NEXT CLASS FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
Copyright © 2006 Sun Microsystems, Inc. and Motorola, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.
For more information, please consult the JSR 118 specification.
分享到:
相关推荐
这个“J2ME中文API(自己翻译的)初学者用”文件,显然是为初学者提供的一份中文版J2ME API参考,便于理解和学习。以下将详细介绍其中涉及的一些关键类和接口: 1. **Alert**:用于在用户界面上显示一个包含消息的...
这对于想要学习J2ME开发的人来说是非常实用的资料。通过这个例子,读者不仅可以了解到如何构建基本的数据模型,还能学习到如何处理数据的存储和检索,这对于开发移动应用非常有帮助。 尽管原始代码中存在一些错误和...
它使用 `DataOutputStream` 将每个字段写入一个 `ByteArrayOutputStream`,然后将其转换为字节数组。 `initAppointment()` 方法则相反,它从字节数组中读取数据,使用 `DataInputStream` 来解析字节流并初始化记录...
ByteArrayOutputStream byte_Out = new ByteArrayOutputStream(); DataOutputStream data_Out = new DataOutputStream( byte_Out ); int size = vector1.size(); data_Out.writeInt( size ); for( int i = 0; i...
根据给定的信息,本文将详细探讨“J2ME平台下文本阅读器的实现”,包括其关键技术、实现步骤以及相关的背景信息。 ### J2ME平台下文本阅读器的实现 #### 引言 随着移动通信技术和互联网技术的快速发展,智能手机...
在Java ME(J2ME)平台上,gzip压缩是一种常见的数据压缩技术,用于减小应用程序的传输数据量,提高网络通信效率。本篇文章将深入探讨J2ME中的gzip压缩原理、实现方式以及应用。 gzip是一种广泛使用的文件压缩格式...
**建立连接**:当用户点击“发送”按钮时,程序会创建一个 `ByteArrayOutputStream` 和 `DataOutputStream`,用于将用户输入的数据序列化并存储到 `byte[]` 数组中。 3. **发起请求**:接着创建一个新的线程来执行...
J2ME仅保留了InputStream、ByteArrayInputStream、DataInputStream、OutputStream、ByteArrayOutputStream和DataOutputStream等基本流操作,这意味着JZlib中涉及的FilterInputStream等高级流处理类无法直接使用。...
在IT行业中,J2ME(Java 2 Micro Edition)是一种广泛应用于移动设备和嵌入式系统的Java编程平台。本文将深入探讨如何在J2ME环境中进行系统文件操作,特别是涉及图片处理,包括将图片转化为byte数组的过程。 首先,...
小剑士import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Random; import javax.microedition.lcdui.*; import javax.microedition.rms....
J2ME,全称Java 2 Micro Edition,是Java平台的一个子集,主要用于开发和部署在移动设备、嵌入式设备以及消费电子设备...这本手册为开发者提供了快速查找和学习J2ME API的途径,有助于他们更有效地进行移动应用的开发。
- **ByteArrayOutputStream**: 向字节数组写入数据的输出流。 - **DataInputStream**: 从输入流中读取基本类型的数据。 - **DataOutputStream**: 向输出流写入基本类型的数据。 - **InputStream**: 输入流的基类。 -...
根据提供的文件信息,我们可以深入分析J2ME浏览器源码中的关键知识点。...这对于学习J2ME开发和理解其工作原理非常有帮助。此外,通过对这些API的深入理解,开发者可以更有效地利用J2ME来创建丰富的移动应用程序。
尽管可能不如现代智能机上的解决方案那样性能强大,但它提供了一个基础框架,对于学习音频处理和移动应用开发具有一定的教育价值。开发者可以在此基础上进行优化,例如减少缓冲造成的延迟,或者提升图形绘制的效率,...
`ByteArrayInputStream`和`ByteArrayOutputStream`用于处理字节数组输入输出。`DataInputStream`和`DataOutputStream`用于读写基本数据类型。`InputStream`和`OutputStream`是所有输入输出流的基类,它们支持基本的...
8. **ByteArrayInputStream/ByteArrayOutputStream**: 提供基于内存的字节流实现,用于读写字节数组。 9. **Calendar**: 提供操作日期和时间的方法。 10. **Canvas**: 用于绘制图形和处理用户输入的基本组件。 ...
9. **ByteArrayOutputStream**: 将数据写入字节数组的输出流。 10. **Calendar**: 提供了对日期和时间的处理方法,包括获取当前日期时间、格式化日期等。 11. **Canvas**: 提供了一种绘制图形的方法,通常用于游戏...
`java.io.ByteArrayOutputStream`和`java.io.ByteArrayInputStream`可以在这方面提供帮助。 - **文件大小检查**:在复制前检查源文件和目标文件的可用空间,确保有足够的空间进行复制,避免溢出问题。 - **同步...
虽然这些技术随着时代的发展可能不再是最新的选择,但它们所蕴含的设计思想和技术细节仍然值得学习和借鉴。在现代应用开发中,虽然技术栈已经更新换代,但理解底层原理对于掌握新技术仍然非常重要。