本文整理匯總了Java中java.io.CharArrayReader.read方法的典型用法代碼示例。如果您正苦於以下問題:Java CharArrayReader.read方法的具體用法?Java CharArrayReader.read怎麽用?Java CharArrayReader.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.CharArrayReader
的用法示例。
在下文中一共展示了CharArrayReader.read方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_markI
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* java.io.CharArrayReader#mark(int)
*/
public void test_markI() throws IOException {
cr = new CharArrayReader(hw);
cr.skip(5L);
cr.mark(100);
cr.read();
cr.reset();
assertEquals("Test 1: Failed to mark correct position;",
'W', cr.read());
cr.close();
try {
cr.mark(100);
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
示例2: test_reset
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* java.io.CharArrayReader#reset()
*/
public void test_reset() throws IOException {
cr = new CharArrayReader(hw);
cr.skip(5L);
cr.mark(100);
cr.read();
cr.reset();
assertEquals("Test 1: Reset failed to return to marker position.",
'W', cr.read());
cr.close();
try {
cr.reset();
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
示例3: reset
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* @tests java.io.CharArrayWriter#reset()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies reset() method.",
method = "reset",
args = {}
)
public void test_reset() {
// Test for method void java.io.CharArrayWriter.reset()
cw.write("HelloWorld", 5, 5);
cw.reset();
cw.write("HelloWorld", 0, 5);
cr = new CharArrayReader(cw.toCharArray());
try {
char[] c = new char[100];
cr.read(c, 0, 5);
assertEquals("Reset failed to reset buffer",
"Hello", new String(c, 0, 5));
} catch (IOException e) {
fail("Exception during reset test : " + e.getMessage());
}
}
示例4: toCharArray
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* @tests java.io.CharArrayWriter#toCharArray()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies toCharArray() method.",
method = "toCharArray",
args = {}
)
public void test_toCharArray() {
// Test for method char [] java.io.CharArrayWriter.toCharArray()
cw.write("HelloWorld", 0, 10);
cr = new CharArrayReader(cw.toCharArray());
try {
char[] c = new char[100];
cr.read(c, 0, 10);
assertEquals("toCharArray failed to return correct array",
"HelloWorld", new String(c, 0, 10));
} catch (IOException e) {
fail("Exception during toCharArray test : " + e.getMessage());
}
}
示例5: CharArrayReader
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* @tests java.io.CharArrayWriter#write(char[], int, int)
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
method = "write",
args = {char[].class, int.class, int.class}
)
public void test_write$CII() {
// Test for method void java.io.CharArrayWriter.write(char [], int, int)
cw.write(hw, 5, 5);
cr = new CharArrayReader(cw.toCharArray());
try {
char[] c = new char[100];
cr.read(c, 0, 5);
assertEquals("Writer failed to write correct chars",
"World", new String(c, 0, 5));
} catch (IOException e) {
fail("Exception during write test : " + e.getMessage());
}
}
示例6: write
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies write(java.lang.String, int, int) method. [Need to check different strings?]",
method = "write",
args = {java.lang.String.class, int.class, int.class}
)
public void test_writeLjava_lang_StringII() {
// Test for method void java.io.CharArrayWriter.write(java.lang.String,
// int, int)
cw.write("HelloWorld", 5, 5);
cr = new CharArrayReader(cw.toCharArray());
try {
char[] c = new char[100];
cr.read(c, 0, 5);
assertEquals("Writer failed to write correct chars",
"World", new String(c, 0, 5));
} catch (IOException e) {
fail("Exception during write test : " + e.getMessage());
}
}
示例7: close
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* @tests java.io.CharArrayReader#close()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies close() method.",
method = "close",
args = {}
)
public void test_close() {
cr = new CharArrayReader(hw);
cr.close();
try {
cr.read();
fail("Failed to throw exception on read from closed stream");
} catch (IOException e) {
// Expected.
}
}
示例8: test_markI
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* @tests java.io.CharArrayReader#mark(int)
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "mark",
args = {int.class}
)
public void test_markI() throws IOException {
// Test for method void java.io.CharArrayReader.mark(int)
cr = new CharArrayReader(hw);
cr.skip(5L);
cr.mark(100);
cr.read();
cr.reset();
assertEquals("Test 1: Failed to mark correct position;",
'W', cr.read());
cr.close();
try {
cr.mark(100);
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
示例9: test_reset
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* @tests java.io.CharArrayReader#reset()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
method = "reset",
args = {}
)
public void test_reset() throws IOException {
cr = new CharArrayReader(hw);
cr.skip(5L);
cr.mark(100);
cr.read();
cr.reset();
assertEquals("Test 1: Reset failed to return to marker position.",
'W', cr.read());
cr.close();
try {
cr.reset();
fail("Test 2: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
示例10: writeSBToStreamEfficiently
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* A memory efficient way to write a StringBuffer to an OutputStream
* without creating Strings and other Objects.
* <p/>
* Mar 9, 2012
*
* @param aSB
* @param ous
* @throws IOException
*/
// public static void writeSBToStreamEfficiently(StringBuffer aSB, OutputStream ous) throws IOException{
public static void writeSBToStreamEfficiently( StringBuffer aSB, Writer ous ) throws IOException
{
final int aLength = aSB.length();
final int aChunk = 1024;
final char[] aChars = new char[aChunk]; //aPosEnd-aPosStart]; //aChunk];
for( int aPosStart = 0; aPosStart < aLength; aPosStart += aChunk )
{
final int aPosEnd = Math.min( aPosStart + aChunk, aLength );
aSB.getChars( aPosStart, aPosEnd, aChars, 0 ); // Create no new buffer
final CharArrayReader aCARead = new CharArrayReader( aChars ); // Create no new buffer
// This may be slow but it will not create any more buffer (for bytes)
int aByte;
int i = 0;
while( ((aByte = aCARead.read()) != -1) && (i++ < (aPosEnd - aPosStart)) )
{
ous.write( aByte );
}
}
}
示例11: test_close
import java.io.CharArrayReader; //導入方法依賴的package包/類
/**
* java.io.CharArrayReader#close()
*/
public void test_close() {
cr = new CharArrayReader(hw);
cr.close();
try {
cr.read();
fail("Failed to throw exception on read from closed stream");
} catch (IOException e) {
// Expected.
}
}
示例12: testDefault
import java.io.CharArrayReader; //導入方法依賴的package包/類
@Test
public void testDefault() throws IOException {
char[] chars = "The CharArrayReader class enables you to read the contents of a char array as a character stream".toCharArray();
CharArrayReader reader = new CharArrayReader(chars);
int data = reader.read();
while (data != -1) {
System.out.print((char) data);
data = reader.read();
}
System.out.println();
}
示例13: testReadChars
import java.io.CharArrayReader; //導入方法依賴的package包/類
@Test
public void testReadChars() throws IOException {
char[] chars = "The CharArrayReader class enables you to read the contents of a char array as a character stream".toCharArray();
CharArrayReader reader = new CharArrayReader(chars);
int length = 5;
char[] b = new char[length];
int readLength = reader.read(b);
while (readLength != -1) {
System.out.print(new String(b, 0, readLength));
readLength = reader.read(b);
}
System.out.println();
}
示例14: testReadCharsOffLen
import java.io.CharArrayReader; //導入方法依賴的package包/類
@Test
public void testReadCharsOffLen() throws IOException {
char[] chars = "The CharArrayReader class enables you to read the contents of a char array as a character stream".toCharArray();
CharArrayReader reader = new CharArrayReader(chars);
int length = 5;
char[] b = new char[length];
int readLength = reader.read(b, 0, length);
while (readLength != -1) {
System.out.print(new String(b, 0, readLength));
readLength = reader.read(b, 0, length);
}
System.out.println();
}
示例15: testReadCharsOffLen2
import java.io.CharArrayReader; //導入方法依賴的package包/類
@Test
public void testReadCharsOffLen2() throws IOException {
char[] chars = "The CharArrayReader class enables you to read the contents of a char array as a character stream".toCharArray();
CharArrayReader reader = new CharArrayReader(chars, 0, 5);
int data = reader.read();
while (data != -1) {
System.out.print((char) data);
data = reader.read();
}
System.out.println();
}