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;
}
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) {
}
}
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) {
}
}
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;
}
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);
}
Aggregations