本文整理汇总了Java中java.io.CharArrayReader类的典型用法代码示例。如果您正苦于以下问题:Java CharArrayReader类的具体用法?Java CharArrayReader怎么用?Java CharArrayReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CharArrayReader类属于java.io包,在下文中一共展示了CharArrayReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLength
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void testLength() throws Exception {
FileBackedClob c;
c = new FileBackedClob(new CharArrayReader(testCase1));
assertEquals(c.length(), testCase1.length);
assertEquals(c.getBackingFile().length(), testCase1.length * 4);
c.free();
c = new FileBackedClob(new String(testCase2));
assertEquals(c.length(), testCase2.length);
assertEquals(c.getBackingFile().length(), testCase2.length * 4);
c.free();
c = new FileBackedClob(new CharArrayReader(testCase3));
assertEquals(c.length(), testCase3.length);
assertEquals(c.getBackingFile().length(), testCase3.length * 4);
c.free();
}
示例2: testTruncate
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void testTruncate() throws Exception {
FileBackedClob c;
c = new FileBackedClob(new CharArrayReader(testCase1));
c.truncate(5);
assertEquals(c.length(), 5);
assertEquals(c.getBackingFile().length(), 5 * 4);
c.free();
c = new FileBackedClob(new String(testCase2));
c.truncate(42);
assertEquals(c.length(), 42);
assertEquals(c.getBackingFile().length(), 42 * 4);
c.free();
c = new FileBackedClob(new CharArrayReader(testCase3));
c.truncate(1024);
assertEquals(c.length(), 1024);
assertEquals(c.getBackingFile().length(), 1024 * 4);
c.free();
}
示例3: testGetSubString
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void testGetSubString() throws Exception {
FileBackedClob c;
char[] referenceChars = new char[5];
System.arraycopy(testCase1, 5, referenceChars, 0, 5);
String reference = new String(referenceChars);
c = new FileBackedClob(new CharArrayReader(testCase1));
assertEquals(reference, c.getSubString(6, 5));
c.free();
c = new FileBackedClob(new String(testCase2));
assertEquals( reference, c.getSubString(6, 5));
c.free();
c = new FileBackedClob(new CharArrayReader(testCase3));
assertEquals(reference, c.getSubString(6, 5));
c.free();
}
示例4: testSetString_long_String
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void testSetString_long_String() throws Exception {
FileBackedClob b;
char[] test1 = "test".toCharArray();
char[] test2 = "test0123456789".toCharArray();
char[] firstPartReference = new char[testCase2.length - test1.length - 4];
char[] secondPartReference = new char[4];
System.arraycopy(testCase2, 0, firstPartReference, 0, testCase2.length - test1.length - 4);
System.arraycopy(testCase2, testCase2.length - 4 - 1, secondPartReference, 0, 4);
b = new FileBackedClob(new CharArrayReader(testCase2));
b.setString(testCase2.length - test1.length - 4 + 1, new String(test1));
assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
assertEquals(new String(secondPartReference), b.getSubString(testCase2.length - 4, 4));
assertEquals(new String(test1), b.getSubString(testCase2.length - 4 - test1.length + 1, test1.length));
assertEquals(b.length(), 1024);
b.setString(testCase2.length - test1.length - 4 + 1, new String(test2));
assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
assertEquals(b.length(), 1024 - test1.length - 4 + test2.length);
assertEquals(new String(test2), b.getSubString(b.length() - test2.length + 1, test2.length));
b.free();
}
示例5: testSetString_4args
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void testSetString_4args() throws Exception {
FileBackedClob b;
char[] test1 = "test".toCharArray();
char[] test2 = "01test23456789".toCharArray();
char[] firstPartReference = new char[testCase2.length - test1.length - 4];
char[] secondPartReference = new char[4];
System.arraycopy(testCase2, 0, firstPartReference, 0, testCase2.length - test1.length - 4);
System.arraycopy(testCase2, testCase2.length - 4 - 1, secondPartReference, 0, 4);
b = new FileBackedClob(new CharArrayReader(testCase2));
b.setString(testCase2.length - test1.length - 4 + 1, new String(test2), 2, 4);
assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
assertEquals(new String(secondPartReference), b.getSubString(testCase2.length - 4, 4));
assertEquals(new String(test1), b.getSubString(testCase2.length - 4 - test1.length + 1, test1.length));
assertEquals(b.length(), 1024);
b.free();
}
示例6: testSetCharacterStream
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void testSetCharacterStream() throws Exception {
FileBackedClob b;
char[] test1 = "test".toCharArray();
char[] test2 = "test0123456789".toCharArray();
char[] firstPartReference = new char[testCase2.length - test1.length - 4];
char[] secondPartReference = new char[4];
System.arraycopy(testCase2, 0, firstPartReference, 0, testCase2.length - test1.length - 4);
System.arraycopy(testCase2, testCase2.length - 4 - 1, secondPartReference, 0, 4);
b = new FileBackedClob(new CharArrayReader(testCase2));
Writer os = b.setCharacterStream(testCase2.length - test1.length - 4 + 1);
os.write(test1);
os.close();
assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
assertEquals(new String(secondPartReference), b.getSubString(testCase2.length - 4, 4));
assertEquals(new String(test1), b.getSubString(testCase2.length - 4 - test1.length + 1, test1.length));
assertEquals(b.length(), 1024);
os = b.setCharacterStream(testCase2.length - test1.length - 4 + 1);
os.write(test2);
os.close();
assertEquals(new String(firstPartReference), b.getSubString(1, testCase2.length - test1.length - 4));
assertEquals(b.length(), 1024 - test1.length - 4 + test2.length);
assertEquals(new String(test2), b.getSubString(b.length() - test2.length + 1, test2.length));
b.free();
}
示例7: verifyUserSig
import java.io.CharArrayReader; //导入依赖的package包/类
@Override
public boolean verifyUserSig(String identifier, String sig)throws QCloudException {
try {
Security.addProvider(new BouncyCastleProvider());
//DeBaseUrl64 urlSig to json
Base64 decoder = new Base64();
byte [] compressBytes = Base64Url.base64DecodeUrl(sig.getBytes(Charset.forName("UTF-8")));
//Decompression
Inflater decompression = new Inflater();
decompression.setInput(compressBytes, 0, compressBytes.length);
byte [] decompressBytes = new byte [1024];
int decompressLength = decompression.inflate(decompressBytes);
decompression.end();
String jsonString = new String(Arrays.copyOfRange(decompressBytes, 0, decompressLength));
//Get TLS.Sig from json
JSONObject jsonObject= JSON.parseObject(jsonString);
String sigTLS = jsonObject.getString("TLS.sig");
//debase64 TLS.Sig to get serailString
byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));
String strSdkAppid = jsonObject.getString("TLS.sdk_appid");
String sigTime = jsonObject.getString("TLS.time");
String sigExpire = jsonObject.getString("TLS.expire_after");
if (!imConfig.getSdkAppId().equals(strSdkAppid))
{
return false;
}
if ( System.currentTimeMillis()/1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
return false;
}
//Get Serial String from json
String SerialString =
"TLS.appid_at_3rd:" + 0 + "\n" +
"TLS.account_type:" + 0 + "\n" +
"TLS.identifier:" + identifier + "\n" +
"TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" +
"TLS.time:" + sigTime + "\n" +
"TLS.expire_after:" + sigExpire + "\n";
Reader reader = new CharArrayReader(imConfig.getPublicKey().toCharArray());
PEMParser parser = new PEMParser(reader);
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
Object obj = parser.readObject();
parser.close();
PublicKey pubKeyStruct = converter.getPublicKey((SubjectPublicKeyInfo) obj);
Signature signature = Signature.getInstance("SHA256withECDSA","BC");
signature.initVerify(pubKeyStruct);
signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
return signature.verify(signatureBytes);
}catch (Exception e) {
throw new QCloudException(e);
}
}
示例8: main
import java.io.CharArrayReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
char[] a = "_123456789_123456789_123456789_123456789"
.toCharArray(); // a.length > 33
try (CharArrayReader car = new CharArrayReader(a)) {
long small = 33;
long big = Long.MAX_VALUE;
long smallSkip = car.skip(small);
if (smallSkip != small)
throw new Exception("Expected to skip " + small
+ " chars, but skipped " + smallSkip);
long expSkip = a.length - small;
long bigSkip = car.skip(big);
if (bigSkip != expSkip)
throw new Exception("Expected to skip " + expSkip
+ " chars, but skipped " + bigSkip);
}
}
示例9: main
import java.io.CharArrayReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
char[] a = "_123456789_123456789_123456789_123456789"
.toCharArray(); // a.length > 33
try (CharArrayReader car = new CharArrayReader(a)) {
int len1 = 33;
char[] buf1 = new char[len1];
if (car.read(buf1, 0, len1) != len1)
throw new Exception("Expected to read " + len1 + " chars");
int len2 = Integer.MAX_VALUE - 32;
char[] buf2 = new char[len2];
int expLen2 = a.length - len1;
if (car.read(buf2, 0, len2) != expLen2)
throw new Exception("Expected to read " + expLen2 + " chars");
}
}
示例10: main
import java.io.CharArrayReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
int N = 10;
for (int i = 0; i < N; i++) {
HTMLEditorKit kit = new HTMLEditorKit();
Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
htmlReader.flush();
CharArrayWriter writer = new CharArrayWriter(1000);
kit.write(writer, doc, 0, doc.getLength());
writer.flush();
String result = writer.toString();
if (!result.contains("<tt><a")) {
throw new RuntimeException("The <a> and <tt> tags are swapped");
}
}
}
示例11: main
import java.io.CharArrayReader; //导入依赖的package包/类
public static void main(String[] args) {
String htmlDoc = "<pre><p> </pre>";
try {
HTMLEditorKit kit = new HTMLEditorKit();
Class c = Class.forName(
"javax.swing.text.html.parser.ParserDelegator");
HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
parser.parse(new CharArrayReader(htmlDoc.toCharArray()),
htmlReader, true);
htmlReader.flush();
CharArrayWriter writer = new CharArrayWriter(1000);
kit.write(writer, doc, 0, doc.getLength());
writer.flush();
} catch (Exception ex) {
throw new RuntimeException("Test Failed " + ex);
}
}
示例12: decode
import java.io.CharArrayReader; //导入依赖的package包/类
/**
* Decode a string back to a byte array.
*
* @param s the string to convert
* @param uncompress use gzip to uncompress the stream of bytes
*
* @throws IOException if there's a gzip exception
*/
public static byte[] decode(final String s, final boolean uncompress) throws IOException {
byte[] bytes;
try (JavaReader jr = new JavaReader(new CharArrayReader(s.toCharArray()));
ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
int ch;
while ((ch = jr.read()) >= 0) {
bos.write(ch);
}
bytes = bos.toByteArray();
}
if (uncompress) {
final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
final byte[] tmp = new byte[bytes.length * 3]; // Rough estimate
int count = 0;
int b;
while ((b = gis.read()) >= 0) {
tmp[count++] = (byte) b;
}
bytes = new byte[count];
System.arraycopy(tmp, 0, bytes, 0, count);
}
return bytes;
}
示例13: converterSelectedByControlRecord
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void converterSelectedByControlRecord() throws Exception {
String type1 = "type1";
String type2 = "type2";
String input = formatInput("!{0}\n" + NAME.code() + "\n^\n!{1}\n" + DATE.code() + "\n^\n", type1, type2);
List<RecordConverter> converters = createConverterMocks(type1, type2);
QifImport qifImport = new QifImport(converters);
qifImport.importFile(new CharArrayReader(input.toCharArray()), messageConsumer);
ArgumentCaptor<QifRecord> capture0 = ArgumentCaptor.forClass(QifRecord.class);
ArgumentCaptor<QifRecord> capture1 = ArgumentCaptor.forClass(QifRecord.class);
verify(converters.get(0)).importRecord(isA(AccountHolder.class), capture0.capture());
verify(converters.get(1)).importRecord(isA(AccountHolder.class), capture1.capture());
assertThat(capture0.getValue().hasValue(NAME)).isTrue();
assertThat(capture0.getValue().hasValue(DATE)).isFalse();
assertThat(capture1.getValue().hasValue(DATE)).isTrue();
assertThat(capture1.getValue().hasValue(NAME)).isFalse();
}
示例14: exceptionThrownForInvalidRecord
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void exceptionThrownForInvalidRecord() throws Exception {
String type = "type";
String input = formatInput("!{0}\n" + NAME.code() + "\n!\n", type);
List<RecordConverter> converters = createConverterMocks(type);
QifImport qifImport = new QifImport(converters);
try {
qifImport.importFile(new CharArrayReader(input.toCharArray()), messageConsumer);
fail("expected an exception");
}
catch (QuickenException ex) {
assertThat(ex.getMessageKey()).isEqualTo("import.qif.invalidRecord");
assertThat(ex.getMessageArgs()).isEqualTo(new Object[] {"QIF", 2L});
}
}
示例15: quickenExceptionsNotCaught
import java.io.CharArrayReader; //导入依赖的package包/类
@Test
public void quickenExceptionsNotCaught() throws Exception {
String type = "type";
String input = formatInput("!{0}\n" + NAME.code() + "\n^\n^\n" + DATE.code() + "\n^\n" + DATE.code() + "\n^\n", type);
List<RecordConverter> converters = createConverterMocks(type);
RecordConverter converter = converters.get(0);
QuickenException cause = new QuickenException("key", "one", 1L);
doThrow(cause).when(converter).importRecord(isA(AccountHolder.class), isA(QifRecord.class));
QifImport qifImport = new QifImport(converters);
try {
qifImport.importFile(new CharArrayReader(input.toCharArray()), messageConsumer);
fail("expected an exception");
} catch (QuickenException ex) {
assertThat(ex).isSameAs(cause);
}
}