Search in sources :

Example 61 with CharArrayReader

use of java.io.CharArrayReader in project intellij-community by JetBrains.

the class InspectionTestUtil method compareDescriptions.

static boolean compareDescriptions(Element reportedProblem, Element expectedProblem) throws Exception {
    String expectedDescription = expectedProblem.getChildText("description");
    String reportedDescription = reportedProblem.getChildText("description");
    if (expectedDescription.equals(reportedDescription))
        return true;
    StreamTokenizer tokenizer = new StreamTokenizer(new CharArrayReader(expectedDescription.toCharArray()));
    tokenizer.quoteChar('\'');
    int idx = 0;
    while (tokenizer.nextToken() != StreamTokenizer.TT_EOF) {
        String word;
        if (tokenizer.sval != null) {
            word = tokenizer.sval;
        } else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) {
            word = Double.toString(tokenizer.nval);
        } else {
            continue;
        }
        idx = reportedDescription.indexOf(word, idx);
        if (idx == -1)
            return false;
        idx += word.length();
    }
    return true;
}
Also used : CharArrayReader(java.io.CharArrayReader) StreamTokenizer(java.io.StreamTokenizer)

Example 62 with CharArrayReader

use of java.io.CharArrayReader in project ACS by ACS-Community.

the class ComponentWithXmlOffshootClientTest method testOffshoot.

public void testOffshoot() throws Exception {
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    XmlOffshoot shoot = componentWithXmlOffshoot.getOffshoot();
    assertNotNull(shoot.getObsProposal());
    assertNotNull(shoot.getSchedBlock());
    // these values are hardcoded in the m_offshoot implementation
    XmlEntityStruct struct = shoot.getObsProposal();
    Document d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("rtobar", d.getElementsByTagName("PI").item(0).getTextContent());
    assertEquals("2010.0045.34S", d.getElementsByTagName("code").item(0).getTextContent());
    assertEquals("just for fun", d.getElementsByTagName("ScientificJustification").item(0).getTextContent());
    struct = shoot.getSchedBlock();
    d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("holography", d.getElementsByTagName("ns2:name").item(0).getTextContent());
    assertEquals("DONE", d.getElementsByTagName("ns1:status").item(0).getTextContent());
    assertEquals("true", d.getElementsByTagName("StandardMode").item(0).getTextContent());
    // just to check the setters
    shoot.setObsProposal(new XmlEntityStruct());
    shoot.setSchedBlock(new XmlEntityStruct());
    // deactivate the m_offshoot on the server-side
    componentWithXmlOffshoot.deactivateOffshoot();
    try {
        shoot.getObsProposal();
        fail("m_offshoot should be deactivated, I shouldn't be able to use it");
    } catch (org.omg.CORBA.OBJECT_NOT_EXIST e) {
    }
}
Also used : InputSource(org.xml.sax.InputSource) CharArrayReader(java.io.CharArrayReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlEntityStruct(alma.xmlentity.XmlEntityStruct) ComponentWithXmlOffshoot(alma.demo.ComponentWithXmlOffshoot) XmlOffshoot(alma.demo.XmlOffshoot) Document(org.w3c.dom.Document)

Example 63 with CharArrayReader

use of java.io.CharArrayReader in project ACS by ACS-Community.

the class XmlComponentClientTest method testOffshoot.

public void testOffshoot() throws Exception {
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    XmlOffshoot shoot = xmlComponent.getOffshoot();
    assertNotNull(shoot.getObsProposal());
    assertNotNull(shoot.getSchedBlock());
    // these values are hardcoded in the m_offshoot implementation
    XmlEntityStruct struct = shoot.getObsProposal();
    Document d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("rtobar", d.getElementsByTagName("PI").item(0).getTextContent());
    assertEquals("2010.0045.34S", d.getElementsByTagName("code").item(0).getTextContent());
    assertEquals("just for fun", d.getElementsByTagName("ScientificJustification").item(0).getTextContent());
    struct = shoot.getSchedBlock();
    d = db.parse(new InputSource(new CharArrayReader(struct.xmlString.toCharArray())));
    assertEquals("holography", d.getElementsByTagName("ns2:name").item(0).getTextContent());
    assertEquals("DONE", d.getElementsByTagName("ns1:status").item(0).getTextContent());
    assertEquals("true", d.getElementsByTagName("StandardMode").item(0).getTextContent());
    // just to check the setters
    shoot.setObsProposal(new XmlEntityStruct());
    shoot.setSchedBlock(new XmlEntityStruct());
    // deactivate the m_offshoot on the server-side
    xmlComponent.deactivateOffshoot();
    try {
        shoot.getObsProposal();
        fail("m_offshoot should be deactivated, I shouldn't be able to use it");
    } catch (org.omg.CORBA.OBJECT_NOT_EXIST e) {
    }
}
Also used : InputSource(org.xml.sax.InputSource) CharArrayReader(java.io.CharArrayReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XmlEntityStruct(alma.xmlentity.XmlEntityStruct) XmlOffshoot(alma.demo.XmlOffshoot) Document(org.w3c.dom.Document)

Example 64 with CharArrayReader

use of java.io.CharArrayReader in project voltdb by VoltDB.

the class ClosableCharArrayWriter method toCharArrayReader.

/**
     * Performs an effecient (zero-copy) conversion of the character data
     * accumulated in this writer to a reader. <p>
     *
     * To ensure the integrity of the resulting reader, {@link #free()
     * free} is invoked upon this writer as a side-effect.
     *
     * @return a reader representing this writer's accumulated
     *      character data
     * @throws java.io.IOException if an I/O error occurs.
     *      In particular, an <tt>IOException</tt> may be thrown
     *      if this writer has been {@link #free() freed}.
     */
public synchronized CharArrayReader toCharArrayReader() throws IOException {
    checkFreed();
    CharArrayReader reader = new CharArrayReader(buf, 0, count);
    //System.out.println("toCharArrayReader::buf.length: " + buf.length);
    free();
    return reader;
}
Also used : CharArrayReader(java.io.CharArrayReader)

Example 65 with CharArrayReader

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

the class DataFlavor method getReaderForText.

/**
     * Gets a Reader for a text flavor, decoded, if necessary, for the expected
     * charset (encoding). The supported representation classes are
     * <code>java.io.Reader</code>, <code>java.lang.String</code>,
     * <code>java.nio.CharBuffer</code>, <code>[C</code>,
     * <code>java.io.InputStream</code>, <code>java.nio.ByteBuffer</code>,
     * and <code>[B</code>.
     * <p>
     * Because text flavors which do not support the charset parameter are
     * encoded in a non-standard format, this method should not be called for
     * such flavors. However, in order to maintain backward-compatibility,
     * if this method is called for such a flavor, this method will treat the
     * flavor as though it supports the charset parameter and attempt to
     * decode it accordingly. See <code>selectBestTextFlavor</code> for a list
     * of text flavors which do not support the charset parameter.
     *
     * @param transferable the <code>Transferable</code> whose data will be
     *        requested in this flavor
     *
     * @return a <code>Reader</code> to read the <code>Transferable</code>'s
     *         data
     *
     * @exception IllegalArgumentException if the representation class
     *            is not one of the seven listed above
     * @exception IllegalArgumentException if the <code>Transferable</code>
     *            has <code>null</code> data
     * @exception NullPointerException if the <code>Transferable</code> is
     *            <code>null</code>
     * @exception UnsupportedEncodingException if this flavor's representation
     *            is <code>java.io.InputStream</code>,
     *            <code>java.nio.ByteBuffer</code>, or <code>[B</code> and
     *            this flavor's encoding is not supported by this
     *            implementation of the Java platform
     * @exception UnsupportedFlavorException if the <code>Transferable</code>
     *            does not support this flavor
     * @exception IOException if the data cannot be read because of an
     *            I/O error
     * @see #selectBestTextFlavor
     * @since 1.3
     */
public Reader getReaderForText(Transferable transferable) throws UnsupportedFlavorException, IOException {
    Object transferObject = transferable.getTransferData(this);
    if (transferObject == null) {
        throw new IllegalArgumentException("getTransferData() returned null");
    }
    if (transferObject instanceof Reader) {
        return (Reader) transferObject;
    } else if (transferObject instanceof String) {
        return new StringReader((String) transferObject);
    } else if (transferObject instanceof CharBuffer) {
        CharBuffer buffer = (CharBuffer) transferObject;
        int size = buffer.remaining();
        char[] chars = new char[size];
        buffer.get(chars, 0, size);
        return new CharArrayReader(chars);
    } else if (transferObject instanceof char[]) {
        return new CharArrayReader((char[]) transferObject);
    }
    InputStream stream = null;
    if (transferObject instanceof InputStream) {
        stream = (InputStream) transferObject;
    } else if (transferObject instanceof ByteBuffer) {
        ByteBuffer buffer = (ByteBuffer) transferObject;
        int size = buffer.remaining();
        byte[] bytes = new byte[size];
        buffer.get(bytes, 0, size);
        stream = new ByteArrayInputStream(bytes);
    } else if (transferObject instanceof byte[]) {
        stream = new ByteArrayInputStream((byte[]) transferObject);
    }
    if (stream == null) {
        throw new IllegalArgumentException("transfer data is not Reader, String, CharBuffer, char array, InputStream, ByteBuffer, or byte array");
    }
    String encoding = getParameter("charset");
    return (encoding == null) ? new InputStreamReader(stream) : new InputStreamReader(stream, encoding);
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CharBuffer(java.nio.CharBuffer) CharArrayReader(java.io.CharArrayReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) ByteBuffer(java.nio.ByteBuffer) CharArrayReader(java.io.CharArrayReader) ByteArrayInputStream(java.io.ByteArrayInputStream) StringReader(java.io.StringReader)

Aggregations

CharArrayReader (java.io.CharArrayReader)102 IOException (java.io.IOException)45 BufferedReader (java.io.BufferedReader)22 Reader (java.io.Reader)19 File (java.io.File)11 InputStreamReader (java.io.InputStreamReader)10 Test (org.junit.Test)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 StringReader (java.io.StringReader)8 FileReader (java.io.FileReader)7 PreparedStatement (java.sql.PreparedStatement)7 BufferedWriter (java.io.BufferedWriter)5 CharArrayWriter (java.io.CharArrayWriter)5 FileWriter (java.io.FileWriter)5 InputStream (java.io.InputStream)5 ResultSet (java.sql.ResultSet)5 InputSource (org.xml.sax.InputSource)5 PipedReader (java.io.PipedReader)4 CharBuffer (java.nio.CharBuffer)4 Signature (java.security.Signature)4