java.io.StringBufferInputStream Java Examples

The following examples show how to use java.io.StringBufferInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: openxds   Author: jembi   File: MultipartMap.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Used for testing and demonstration purposes.
 */
static public void main(String args[]) throws Exception, java.io.IOException {
    try {
        //String xx = "------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:d4bfb124-7922-45bc-a03d-823351eed716\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/transform.html\r\n------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:45b90888-49c1-4b64-a8eb-e94f541368f0\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/rawSQL.html\r\n------=_Part_2_9110923.1073664290010--\r\n";
        String xx = "------_Part_\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:d4bfb124-7922-45bc-a03d-823351eed716\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/transform.html\r\n------_Part_\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:45b90888-49c1-4b64-a8eb-e94f541368f0\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/rawSQL.html\r\n------_Part_--\r\n";
        StringBufferInputStream is = new StringBufferInputStream(xx);
        String contentType = "multipart/related; boundary=----_Part_";
        ByteArrayDataSource ds = new ByteArrayDataSource(is,  contentType);
        //ByteArrayDataSource ds = new ByteArrayDataSource();
        javax.mail.internet.MimeMultipart mp = new javax.mail.internet.MimeMultipart(ds);
        int i = mp.getCount();
    } catch (javax.mail.MessagingException me) {
        throw new Exception("messaging exception in parsing for MultipartMap");
    }
    System.out.println("Done");
}
 
Example #2
Source Project: groovy   Author: apache   File: DependencyTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testTransitiveDep(){
    cu.addSource("testTransitiveDep.gtest", new StringBufferInputStream(
            "class A1 {}\n" +
            "class A2 extends A1{}\n" +
            "class A3 extends A2{}\n"
    ));
    cu.compile(Phases.CLASS_GENERATION);
    cache.makeTransitiveHull();

    Set<String> dep = cache.get("A1");
    assertEquals(dep.size(),1);

    dep = cache.get("A2");
    assertEquals(dep.size(),2);
    assertTrue(dep.contains("A1"));

    dep = cache.get("A3");
    assertEquals(dep.size(),3);
    assertTrue(dep.contains("A1"));
    assertTrue(dep.contains("A2"));
}
 
Example #3
Source Project: android-test   Author: android   File: DomMatchersTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWithBody_DocumentWithNoBody() throws Exception {
  Document documentWithNoBody =
      DocumentBuilderFactory.newInstance()
          .newDocumentBuilder()
          .parse(new StringBufferInputStream(HTML_NO_BODY));

  Matcher<Element> alwaysMatch =
      new TypeSafeMatcher<Element>() {
        @Override
        public void describeTo(Description description) {
          description.appendText("always a match");
        }

        @Override
        public boolean matchesSafely(Element element) {
          return true;
        }
      };
  assertFalse(withBody(alwaysMatch).matches(documentWithNoBody));
}
 
Example #4
Source Project: openbd-core   Author: OpenBD   File: TreeApplet.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Vector getData(String a){
	//-- Put them together
	int x = 0;
	StringBuilder appletP	= new StringBuilder(128);
	String line	= thisApplet.getParameter("treedata" + x);
	while (line!=null){
		appletP.append( line.substring(1,line.length()-1) );
		x++;
		line	= thisApplet.getParameter("treedata" + x);
	}

	String appletParam	= appletP.toString();

	tags		= new Stack();
	params	= new Stack();
	StringBufferInputStream s = new StringBufferInputStream(appletParam);	

	try{
		parseXML(s);
	}catch(Throwable E){
		E.printStackTrace();
		return null;
	}

	return (Vector)params.peek();
}
 
Example #5
Source Project: onos   Author: opennetworkinglab   File: DellRestOpenFlowControllerConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setControllers(List<ControllerInfo> controllers) {

    // Dell supports max 2 controllers per of-instance
    if (controllers.size() > MAX_CONTROLLERS) {
        log.warn("Cannot set more than 2 controllers.");
    }

    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();

    String controllerCommands = getControllerCommands(controllers).stream()
            .reduce(String::concat)
            .orElse("");

    InputStream payload = new StringBufferInputStream(String.format(SET_CONTROLLERS_XML, controllerCommands));
    String resp = controller.post(deviceId, CLI_REQUEST, payload, MediaType.valueOf("*/*"), String.class);
    log.info("{}", resp);
}
 
Example #6
Source Project: onos   Author: opennetworkinglab   File: DellRestBridgeConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void addPort(BridgeName bridgeName, String portName) {
    // bridgeName is not used
    checkNotNull(portName);
    portName = portNameForCli(portName);
    String portAddCommands = String.format(PORT_ADD_COMMANDS, portName);

    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();

    InputStream payload = new StringBufferInputStream(String.format(CONFIG_COMMANDS, portAddCommands));
    String resp = controller.post(deviceId, CLI_REQUEST, payload, MediaType.valueOf("*/*"), String.class);
    //TODO Parse resp and if error, return false
    log.info("{}", resp);
    return;
}
 
Example #7
Source Project: android_9.0.0_r45   Author: lulululbj   File: WebResourceResponse.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the input stream that provides the resource response's data. Callers
 * must implement {@link InputStream#read(byte[])}. {@link InputStream#close()}
 * will be called after the WebView has finished with the response.
 *
 * @param data the input stream that provides the resource response's data. Must not be a
 *             StringBufferInputStream.
 */
public void setData(InputStream data) {
    checkImmutable();
    // If data is (or is a subclass of) StringBufferInputStream
    if (data != null && StringBufferInputStream.class.isAssignableFrom(data.getClass())) {
        throw new IllegalArgumentException("StringBufferInputStream is deprecated and must " +
            "not be passed to a WebResourceResponse");
    }
    mInputStream = data;
}
 
Example #8
Source Project: dragonwell8_jdk   Author: alibaba   File: OverflowInRead.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String s = "_123456789_123456789_123456789_123456789"; // s.length() > 33
    try (StringBufferInputStream sbis = new StringBufferInputStream(s)) {
        int len1 = 33;
        byte[] buf1 = new byte[len1];
        if (sbis.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " bytes");

        int len2 = Integer.MAX_VALUE - 32;
        byte[] buf2 = new byte[len2];
        int expLen2 = s.length() - len1;
        if (sbis.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " bytes");
    }
}
 
Example #9
Source Project: dragonwell8_jdk   Author: alibaba   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #10
Source Project: TencentKona-8   Author: Tencent   File: OverflowInRead.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String s = "_123456789_123456789_123456789_123456789"; // s.length() > 33
    try (StringBufferInputStream sbis = new StringBufferInputStream(s)) {
        int len1 = 33;
        byte[] buf1 = new byte[len1];
        if (sbis.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " bytes");

        int len2 = Integer.MAX_VALUE - 32;
        byte[] buf2 = new byte[len2];
        int expLen2 = s.length() - len1;
        if (sbis.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " bytes");
    }
}
 
Example #11
Source Project: TencentKona-8   Author: Tencent   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #12
Source Project: jdk8u60   Author: chenghanpeng   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #13
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: OverflowInRead.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String s = "_123456789_123456789_123456789_123456789"; // s.length() > 33
    try (StringBufferInputStream sbis = new StringBufferInputStream(s)) {
        int len1 = 33;
        byte[] buf1 = new byte[len1];
        if (sbis.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " bytes");

        int len2 = Integer.MAX_VALUE - 32;
        byte[] buf2 = new byte[len2];
        int expLen2 = s.length() - len1;
        if (sbis.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " bytes");
    }
}
 
Example #14
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #15
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: OverflowInRead.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String s = "_123456789_123456789_123456789_123456789"; // s.length() > 33
    try (StringBufferInputStream sbis = new StringBufferInputStream(s)) {
        int len1 = 33;
        byte[] buf1 = new byte[len1];
        if (sbis.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " bytes");

        int len2 = Integer.MAX_VALUE - 32;
        byte[] buf2 = new byte[len2];
        int expLen2 = s.length() - len1;
        if (sbis.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " bytes");
    }
}
 
Example #16
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #17
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: OverflowInRead.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String s = "_123456789_123456789_123456789_123456789"; // s.length() > 33
    try (StringBufferInputStream sbis = new StringBufferInputStream(s)) {
        int len1 = 33;
        byte[] buf1 = new byte[len1];
        if (sbis.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " bytes");

        int len2 = Integer.MAX_VALUE - 32;
        byte[] buf2 = new byte[len2];
        int expLen2 = s.length() - len1;
        if (sbis.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " bytes");
    }
}
 
Example #18
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #19
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Bug6573786.java    License: GNU General Public License v2.0 5 votes vote down vote up
void runTest(String xmlString) {
    Bug6573786ErrorHandler handler = new Bug6573786ErrorHandler();
    try {
        InputStream is = new StringBufferInputStream(xmlString);
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(is, handler);
    } catch (Exception e) {
        if (handler.fail) {
            Assert.fail("The value of standalone attribute should be merged into the error message.");
        }
    }

}
 
Example #20
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: OverflowInRead.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String s = "_123456789_123456789_123456789_123456789"; // s.length() > 33
    try (StringBufferInputStream sbis = new StringBufferInputStream(s)) {
        int len1 = 33;
        byte[] buf1 = new byte[len1];
        if (sbis.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " bytes");

        int len2 = Integer.MAX_VALUE - 32;
        byte[] buf2 = new byte[len2];
        int expLen2 = s.length() - len1;
        if (sbis.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " bytes");
    }
}
 
Example #21
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #22
Source Project: nifi-minifi   Author: apache   File: ConfigTransformerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void checkSSLOverrides() throws Exception {
    File inputFile = new File("./src/test/resources/MINIFI-516/config.yml");
    final Properties bootstrapProperties = getTestBootstrapProperties("MINIFI-516/bootstrap.conf");
    ConfigTransformer.transformConfigFile(new FileInputStream(inputFile), "./target/", bootstrapProperties);

    // nifi.properties testing
    File nifiPropertiesFile = new File("./target/nifi.properties");
    assertTrue(nifiPropertiesFile.exists());
    assertTrue(nifiPropertiesFile.canRead());

    nifiPropertiesFile.deleteOnExit();

    // flow.xml.gz testing
    File flowXml = new File("./target/flow.xml.gz");
    assertTrue(flowXml.exists());
    assertTrue(flowXml.canRead());

    String flow = loadFlowXML(new FileInputStream(flowXml));

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document xml = db.parse(new StringBufferInputStream(flow));

    XPath xPath = XPathFactory.newInstance().newXPath();
    String result = xPath.evaluate("/flowController/rootGroup/processor/property[name = \"SSL Context Service\"]/value/text()", xml);

    assertEquals(result, "SSL-Context-Service");

    flowXml.deleteOnExit();

}
 
Example #23
Source Project: hottub   Author: dsrg-uoft   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #24
Source Project: jdk8u_jdk   Author: JetBrains   File: OverflowInRead.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String s = "_123456789_123456789_123456789_123456789"; // s.length() > 33
    try (StringBufferInputStream sbis = new StringBufferInputStream(s)) {
        int len1 = 33;
        byte[] buf1 = new byte[len1];
        if (sbis.read(buf1, 0, len1) != len1)
            throw new Exception("Expected to read " + len1 + " bytes");

        int len2 = Integer.MAX_VALUE - 32;
        byte[] buf2 = new byte[len2];
        int expLen2 = s.length() - len1;
        if (sbis.read(buf2, 0, len2) != expLen2)
            throw new Exception("Expected to read " + expLen2 + " bytes");
    }
}
 
Example #25
Source Project: jdk8u_jdk   Author: JetBrains   File: BaseRowSetTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {

    byte[] bytes = new byte[10];
    Ref aRef = new SerialRef(new StubRef("INTEGER", query));
    Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
    Blob aBlob = new SerialBlob(new StubBlob());
    Clob aClob = new SerialClob(new StubClob());
    Reader rdr = new StringReader(query);
    InputStream is = new StringBufferInputStream(query);;
    brs = new StubBaseRowSet();
    brs.setBytes(1, bytes);
    brs.setAsciiStream(2, is, query.length());
    brs.setRef(3, aRef);
    brs.setArray(4, aArray);
    brs.setBlob(5, aBlob);
    brs.setClob(6, aClob);
    brs.setBinaryStream(7, is, query.length());
    brs.setUnicodeStream(8, is, query.length());
    brs.setCharacterStream(9, rdr, query.length());

    return new Object[][]{
        {1, bytes},
        {2, is},
        {3, aRef},
        {4, aArray},
        {5, aBlob},
        {6, aClob},
        {7, is},
        {8, is},
        {9, rdr}
    };
}
 
Example #26
Source Project: development   Author: servicecatalog   File: HttpServletRequestStub.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ServletInputStream getInputStream() throws IOException {

    if (throwExceptionForISAccess) {
        throw new IOException();
    }
    return new BufferedServletInputStream(new StringBufferInputStream(
            bodyContent));
}
 
Example #27
Source Project: the-one   Author: akeranen   File: MovementListenerTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests whether initialLocation() gets called correctly when settings up
 * a SimScenario
 *
 * @throws Exception
 */
@Test
public void testInitialLocation()
throws Exception {
	// TODO: If more test cases are added that use Settings, they might
	// be run in parallel and break.

	// Setup the settings
	Settings.initFromStream(
			new StringBufferInputStream(INITIAL_LOC_TEST_SETTINGS));
	final DTNSimUI ui = new DTNSimUI() {
		@Override
		protected void runSim() {
			super.done();
		}
	};

	// Set the delegate for MovementListenerTestReport
	MovementListenerTestReport.setDelegate(new MovementReport());

	// Start the DTNSimUI, this will create SimScenario instance with all
	// the nodes and reports based on the configuration.
	ui.start();

	assertEquals("initialLocation() called incorrect number of time.",
			INITIAL_LOC_TEST_NODE_COUNT, INITIAL_LOC_CALL_COUNT);
}
 
Example #28
Source Project: openxds   Author: jembi   File: MultipartMap.java    License: Apache License 2.0 5 votes vote down vote up
static public void main(String args[]) throws Exception, java.io.IOException {
    try {
        //String xx = "------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:d4bfb124-7922-45bc-a03d-823351eed716\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/transform.html\r\n------=_Part_2_9110923.1073664290010\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:45b90888-49c1-4b64-a8eb-e94f541368f0\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/rawSQL.html\r\n------=_Part_2_9110923.1073664290010--\r\n";
        String xx = "------_Part_\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:d4bfb124-7922-45bc-a03d-823351eed716\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/transform.html\r\n------_Part_\r\nContent-Type: text/plain\r\nContent-ID: urn:uuid:45b90888-49c1-4b64-a8eb-e94f541368f0\r\n\r\nhttp://ratbert.ncsl.nist.gov:8081/hl7services/rawSQL.html\r\n------_Part_--\r\n";
        StringBufferInputStream is = new StringBufferInputStream(xx);
        String contentType = "multipart/related; boundary=----_Part_";
        ByteArrayDataSource ds = new ByteArrayDataSource(is,  contentType);
        //ByteArrayDataSource ds = new ByteArrayDataSource();
        javax.mail.internet.MimeMultipart mp = new javax.mail.internet.MimeMultipart(ds);
        int i = mp.getCount();
    } catch (javax.mail.MessagingException me) {
        throw new Exception("messaging exception in parsing for MultipartMap");
    }
    System.out.println("Done");
}
 
Example #29
Source Project: openxds   Author: jembi   File: Transform.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the input as a String object.
 * @param input The input String.
 */
public void setInput(String input) {
	int display = 80;
	if (log.isDebugEnabled() ) {
		log.debug("Transform.setInput: " +
				input.substring(0,
						(input.length() < display) ? input.length() : display));
	}
	inputStream = new StringBufferInputStream(input);
	outputStream = new ByteArrayOutputStream();
}
 
Example #30
Source Project: groovy   Author: apache   File: DependencyTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testDep(){
    cu.addSource("testDep.gtest", new StringBufferInputStream(
            "class C1 {}\n" +
            "class C2 {}\n" +
            "class C3 {}\n" +
            "class A1 {C1 x}\n" +
            "class A2 extends C2{}\n" +
            "class A3 {C1 foo(C2 x){new C3()}}\n"
    ));
    cu.compile(Phases.CLASS_GENERATION);
    assertEquals(cache.get("C1").size(),1);
    assertEquals(cache.get("C2").size(),1);
    assertEquals(cache.get("C3").size(),1);

    Set<String> dep = cache.get("A1");
    assertEquals(dep.size(),2);
    assertTrue(dep.contains("C1"));

    dep = cache.get("A2");
    assertEquals(dep.size(),2);
    assertTrue(dep.contains("C2"));

    dep = cache.get("A3");
    assertEquals(dep.size(),4);
    assertTrue(dep.contains("C1"));
    assertTrue(dep.contains("C2"));
    assertTrue(dep.contains("C3"));
}