Search in sources :

Example 26 with CharArrayReader

use of java.io.CharArrayReader in project jdk8u_jdk by JetBrains.

the class DTDInputStream method push.

/**
     * Push a single character
     */
public void push(int ch) throws IOException {
    char[] data = { (char) ch };
    push(new CharArrayReader(data));
}
Also used : CharArrayReader(java.io.CharArrayReader)

Example 27 with CharArrayReader

use of java.io.CharArrayReader in project sketches-core by DataSketches.

the class MemoryMappedFileTest method testReadByAnotherProcess.

@Test
public void testReadByAnotherProcess() {
    File file = new File(getClass().getClassLoader().getResource("memory_mapped.txt").getFile());
    try {
        MemoryMappedFile mmf = MemoryMappedFile.getInstance(file, 0, file.length());
        mmf.load();
        char[] cbuf = new char[500];
        mmf.getCharArray(500, cbuf, 0, 500);
        CharArrayReader car = new CharArrayReader(cbuf);
        MemoryRegion mr = new MemoryRegion(mmf, 500, 3000);
        char[] dst = new char[500];
        mr.getCharArray(0, dst, 0, 500);
        CharArrayReader carMr = new CharArrayReader(dst);
        int value = 0;
        while ((value = car.read()) != -1) {
            assertEquals((char) value, (char) carMr.read());
        }
        mmf.freeMemory();
    } catch (Exception e) {
        fail("Failed: testReadByAnotherProcess()");
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) File(java.io.File) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileNotFoundException(java.io.FileNotFoundException) Test(org.testng.annotations.Test)

Example 28 with CharArrayReader

use of java.io.CharArrayReader in project jdk8u_jdk by JetBrains.

the class bug8005391 method main.

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");
        }
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) CharArrayWriter(java.io.CharArrayWriter)

Example 29 with CharArrayReader

use of java.io.CharArrayReader in project cxf by apache.

the class CachedWriter method getReader.

public Reader getReader() throws IOException {
    flush();
    if (inmem) {
        if (currentStream instanceof LoadingCharArrayWriter) {
            LoadingCharArrayWriter lcaw = (LoadingCharArrayWriter) currentStream;
            return new CharArrayReader(lcaw.rawCharArray(), 0, lcaw.size());
        }
        return null;
    }
    try {
        InputStream fileInputStream = new FileInputStream(tempFile) {

            boolean closed;

            public void close() throws IOException {
                if (!closed) {
                    super.close();
                    maybeDeleteTempFile(this);
                }
                closed = true;
            }
        };
        streamList.add(fileInputStream);
        if (cipherTransformation != null) {
            fileInputStream = new CipherInputStream(fileInputStream, ciphers.getDecryptor()) {

                boolean closed;

                public void close() throws IOException {
                    if (!closed) {
                        super.close();
                        closed = true;
                    }
                }
            };
        }
        return new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
    } catch (FileNotFoundException e) {
        throw new IOException("Cached file was deleted, " + e.toString());
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) CipherInputStream(javax.crypto.CipherInputStream) InputStreamReader(java.io.InputStreamReader) CipherInputStream(javax.crypto.CipherInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 30 with CharArrayReader

use of java.io.CharArrayReader in project leopard by tanhaichao.

the class tls_sigature method CheckTLSSignature.

/**
 * @brief 校验 tls 票据
 * @param urlSig 返回 tls 票据
 * @param strAppid3rd 填写与 sdkAppid 一致的字符串形式的值
 * @param skdAppid 应的 appid
 * @param identifier 用户 id
 * @param accountType 创建应用后在配置页面上展示的 acctype
 * @param publicKey 用于校验 tls 票据的公钥内容,但是需要先将公钥文件转换为 java 原生 api 使用的格式,下面是推荐的命令
 *         openssl pkcs8 -topk8 -in ec_key.pem -outform PEM -out p8_priv.pem -nocrypt
 * @return 如果出错 CheckTLSSignatureResult 中的 verifyResult 为 false,错误信息在 errMsg,校验成功为 true
 * @throws DataFormatException
 */
@Deprecated
public static CheckTLSSignatureResult CheckTLSSignature(String urlSig, String strAppid3rd, long skdAppid, String identifier, long accountType, String publicKey) throws DataFormatException {
    CheckTLSSignatureResult result = new CheckTLSSignatureResult();
    Security.addProvider(new BouncyCastleProvider());
    // DeBaseUrl64 urlSig to json
    Base64 decoder = new Base64();
    // byte [] compressBytes = decoder.decode(urlSig.getBytes());
    byte[] compressBytes = base64_url.base64DecodeUrl(urlSig.getBytes(Charset.forName("UTF-8")));
    // System.out.println("#compressBytes Passing in[" + compressBytes.length + "] " + Hex.encodeHexString(compressBytes));
    // 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));
    // System.out.println("#Json String passing in : \n" + jsonString);
    // Get TLS.Sig from json
    JSONObject jsonObject = new JSONObject(jsonString);
    String sigTLS = jsonObject.getString("TLS.sig");
    // debase64 TLS.Sig to get serailString
    byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));
    try {
        String sigTime = jsonObject.getString("TLS.time");
        String sigExpire = jsonObject.getString("TLS.expire_after");
        // + Long.parseLong(sigTime) + "-" + Long.parseLong(sigExpire));
        if (System.currentTimeMillis() / 1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
            result.errMessage = new String("TLS sig is out of date ");
            System.out.println("Timeout");
            return result;
        }
        // Get Serial String from json
        String SerialString = "TLS.appid_at_3rd:" + strAppid3rd + "\n" + "TLS.account_type:" + accountType + "\n" + "TLS.identifier:" + identifier + "\n" + "TLS.sdk_appid:" + skdAppid + "\n" + "TLS.time:" + sigTime + "\n" + "TLS.expire_after:" + sigExpire + "\n";
        // System.out.println("#SerialString : \n" + SerialString);
        Reader reader = new CharArrayReader(publicKey.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")));
        boolean bool = signature.verify(signatureBytes);
        // System.out.println("#jdk ecdsa verify : " + bool);
        result.verifyResult = bool;
    } catch (Exception e) {
        e.printStackTrace();
        result.errMessage = "Failed in checking sig";
    }
    return result;
}
Also used : Base64(org.apache.commons.codec.binary.Base64) PublicKey(java.security.PublicKey) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader) JcaPEMKeyConverter(org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter) IOException(java.io.IOException) DataFormatException(java.util.zip.DataFormatException) CharArrayReader(java.io.CharArrayReader) JSONObject(org.json.JSONObject) PEMParser(org.bouncycastle.openssl.PEMParser) Signature(java.security.Signature) Inflater(java.util.zip.Inflater) JSONObject(org.json.JSONObject) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Aggregations

CharArrayReader (java.io.CharArrayReader)64 IOException (java.io.IOException)37 BufferedReader (java.io.BufferedReader)16 Reader (java.io.Reader)13 InputStreamReader (java.io.InputStreamReader)8 File (java.io.File)6 FileReader (java.io.FileReader)6 StringReader (java.io.StringReader)6 BufferedWriter (java.io.BufferedWriter)5 CharArrayWriter (java.io.CharArrayWriter)5 FileWriter (java.io.FileWriter)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PipedReader (java.io.PipedReader)4 Signature (java.security.Signature)4 DataFormatException (java.util.zip.DataFormatException)4 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)4 PEMParser (org.bouncycastle.openssl.PEMParser)4 JcaPEMKeyConverter (org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter)4 Document (org.w3c.dom.Document)4 InputStream (java.io.InputStream)3