本文整理匯總了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());
}
}