本文整理汇总了Java中java.io.SequenceInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java SequenceInputStream.read方法的具体用法?Java SequenceInputStream.read怎么用?Java SequenceInputStream.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.SequenceInputStream
的用法示例。
在下文中一共展示了SequenceInputStream.read方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.io.SequenceInputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// SequenceInputStream(InputStream s1, InputStream s2)
// 需求:把ByteArrayStreamDemo.java和DataStreamDemo.java的内容复制到Copy.java中
InputStream s1 = new FileInputStream("ByteArrayStreamDemo.java");
InputStream s2 = new FileInputStream("DataStreamDemo.java");
SequenceInputStream sis = new SequenceInputStream(s1, s2);
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream("Copy.java"));
// 如何写读写呢,其实很简单,你就按照以前怎么读写,现在还是怎么读写
byte[] bys = new byte[1024];
int len = 0;
while ((len = sis.read(bys)) != -1) {
bos.write(bys, 0, len);
}
bos.close();
sis.close();
}
示例2: main
import java.io.SequenceInputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// 需求:把下面的三个文件的内容复制到Copy.java中
// ByteArrayStreamDemo.java,CopyFileDemo.java,DataStreamDemo.java
// SequenceInputStream(Enumeration e)
// 通过简单的回顾我们知道了Enumeration是Vector中的一个方法的返回值类型。
// Enumeration<E> elements()
Vector<InputStream> v = new Vector<InputStream>();
InputStream s1 = new FileInputStream("ByteArrayStreamDemo.java");
InputStream s2 = new FileInputStream("CopyFileDemo.java");
InputStream s3 = new FileInputStream("DataStreamDemo.java");
v.add(s1);
v.add(s2);
v.add(s3);
Enumeration<InputStream> en = v.elements();
SequenceInputStream sis = new SequenceInputStream(en);
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream("Copy.java"));
// 如何写读写呢,其实很简单,你就按照以前怎么读写,现在还是怎么读写
byte[] bys = new byte[1024];
int len = 0;
while ((len = sis.read(bys)) != -1) {
bos.write(bys, 0, len);
}
bos.close();
sis.close();
}
示例3: test_ConstructorLjava_util_Enumeration
import java.io.SequenceInputStream; //导入方法依赖的package包/类
/**
* @tests java.io.SequenceInputStream#SequenceInputStream(java.util.Enumeration)
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "SequenceInputStream",
args = {java.util.Enumeration.class}
)
public void test_ConstructorLjava_util_Enumeration() {
// Test for method java.io.SequenceInputStream(java.util.Enumeration)
class StreamEnumerator implements Enumeration<InputStream> {
InputStream streams[] = new InputStream[2];
int count = 0;
public StreamEnumerator() {
streams[0] = new ByteArrayInputStream(s1.getBytes());
streams[1] = new ByteArrayInputStream(s2.getBytes());
}
public boolean hasMoreElements() {
return count < streams.length;
}
public InputStream nextElement() {
return streams[count++];
}
}
try {
si = new SequenceInputStream(new StreamEnumerator());
byte buf[] = new byte[s1.length() + s2.length()];
si.read(buf, 0, s1.length());
si.read(buf, s1.length(), s2.length());
assertTrue("Read incorrect bytes: " + new String(buf), new String(
buf).equals(s1 + s2));
} catch (IOException e) {
fail("IOException during read test : " + e.getMessage());
}
}
示例4: test
import java.io.SequenceInputStream; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
SequenceInputStream in = new SequenceInputStream(new FileInputStream("file1.log"), new FileInputStream("file2.log"));
int data = in.read();
while (data != -1) {
System.out.print((char) data);
data = in.read();
}
}
示例5: test_ConstructorLjava_util_Enumeration
import java.io.SequenceInputStream; //导入方法依赖的package包/类
/**
* @tests java.io.SequenceInputStream#SequenceInputStream(java.util.Enumeration)
*/
@SuppressWarnings("unchecked")
public void test_ConstructorLjava_util_Enumeration() {
// Test for method java.io.SequenceInputStream(java.util.Enumeration)
class StreamEnumerator implements Enumeration {
InputStream streams[] = new InputStream[2];
int count = 0;
public StreamEnumerator() throws UnsupportedEncodingException {
streams[0] = new ByteArrayInputStream(s1.getBytes("UTF-8"));
streams[1] = new ByteArrayInputStream(s2.getBytes("UTF-8"));
}
public boolean hasMoreElements() {
return count < streams.length;
}
public Object nextElement() {
return streams[count++];
}
}
try {
si = new SequenceInputStream(new StreamEnumerator());
byte buf[] = new byte[s1.length() + s2.length()];
si.read(buf, 0, s1.length());
si.read(buf, s1.length(), s2.length());
assertTrue("Read incorrect bytes: " + new String(buf), new String(
buf, "UTF-8").equals(s1 + s2));
} catch (IOException e) {
fail("IOException during read test : " + e.getMessage());
}
}
示例6: test_ConstructorLjava_util_Enumeration
import java.io.SequenceInputStream; //导入方法依赖的package包/类
/**
* @tests java.io.SequenceInputStream#SequenceInputStream(java.util.Enumeration)
*/
public void test_ConstructorLjava_util_Enumeration() {
// Test for method java.io.SequenceInputStream(java.util.Enumeration)
class StreamEnumerator implements Enumeration {
InputStream streams[] = new InputStream[2];
int count = 0;
public StreamEnumerator() {
streams[0] = new ByteArrayInputStream(s1.getBytes());
streams[1] = new ByteArrayInputStream(s2.getBytes());
}
public boolean hasMoreElements() {
return count < streams.length;
}
public Object nextElement() {
return streams[count++];
}
}
try {
si = new SequenceInputStream(new StreamEnumerator());
byte buf[] = new byte[s1.length() + s2.length()];
si.read(buf, 0, s1.length());
si.read(buf, s1.length(), s2.length());
assertTrue("Read incorrect bytes: " + new String(buf), new String(
buf).equals(s1 + s2));
} catch (IOException e) {
fail("IOException during read test : " + e.getMessage());
}
}