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


Java CharArrayReader類代碼示例

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

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:FileBackedClobTest.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:FileBackedClobTest.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:FileBackedClobTest.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:FileBackedClobTest.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:FileBackedClobTest.java

示例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);
	}
}
 
開發者ID:51wakeup,項目名稱:wakeup-qcloud-sdk,代碼行數:64,代碼來源:DefaultQCloudClient.java

示例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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:OverflowInSkip.java

示例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");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:OverflowInRead.java

示例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");
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:bug8005391.java

示例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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:HTMLEditorKitWriterBug.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:Utility.java

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

示例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});
    }
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:17,代碼來源:QifImportTest.java

示例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);
    }
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:18,代碼來源:QifImportTest.java


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