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


Java SequenceInputStream.read方法代碼示例

本文整理匯總了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();
}
 
開發者ID:aircjm,項目名稱:JavaSeStudy,代碼行數:20,代碼來源:SequenceInputStreamDemo.java

示例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();
}
 
開發者ID:aircjm,項目名稱:JavaSeStudy,代碼行數:30,代碼來源:SequenceInputStreamDemo2.java

示例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());
    }

}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:43,代碼來源:SequenceInputStreamTest.java

示例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();
    }
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:10,代碼來源:SequenceInputStreamTest.java

示例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());
	}

}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:38,代碼來源:SequenceInputStreamTest.java

示例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());
	}

}
 
開發者ID:freeVM,項目名稱:freeVM,代碼行數:37,代碼來源:SequenceInputStreamTest.java


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