Search in sources :

Example 21 with StringBufferInputStream

use of java.io.StringBufferInputStream in project pentaho-platform by pentaho.

the class MondrianCatalogHelperTest method shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven.

@Test(timeout = 2000, expected = SAXException.class)
public void shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven() throws IOException, ParserConfigurationException, SAXException {
    mch.getMondrianXmlDocument(new StringBufferInputStream(XmlTestConstants.MALICIOUS_XML));
    fail();
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) Test(org.junit.Test)

Example 22 with StringBufferInputStream

use of java.io.StringBufferInputStream in project pentaho-platform by pentaho.

the class XActionImportHandlerTest method shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven.

@Test(timeout = 2000, expected = SAXException.class)
public void shouldNotFailAndReturnNullWhenMaliciousXmlIsGiven() throws IOException, ParserConfigurationException, SAXException {
    handler.getImportBundleDocument(new StringBufferInputStream(XmlTestConstants.MALICIOUS_XML));
    fail();
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) Test(org.junit.Test)

Example 23 with StringBufferInputStream

use of java.io.StringBufferInputStream in project pentaho-platform by pentaho.

the class RepositorySyncWebService method getRepositoryMeta.

private static RepositoryMeta getRepositoryMeta(String repositoryId, String repositoryUrl) throws KettleException {
    RepositoryMeta repMeta = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, "PentahoEnterpriseRepository", // $NON-NLS-1$
    RepositoryMeta.class);
    // this repository is not available
    if (repMeta == null) {
        return null;
    }
    String xml = // $NON-NLS-1$
    "<repo>" + // $NON-NLS-1$
    "<id>PentahoEnterpriseRepository</id>" + "<name>" + repositoryId + // $NON-NLS-1$ //$NON-NLS-2$
    "</name>" + "<description>" + repositoryId + // $NON-NLS-1$ //$NON-NLS-2$
    "</description>" + "<repository_location_url>" + repositoryUrl + // $NON-NLS-1$ //$NON-NLS-2$
    "</repository_location_url> </repo>";
    Element node;
    try {
        node = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder().parse(new StringBufferInputStream(xml)).getDocumentElement();
    } catch (Exception e) {
        node = null;
    }
    repMeta.loadXML(node, null);
    return repMeta;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) StringBufferInputStream(java.io.StringBufferInputStream) Element(org.w3c.dom.Element) KettleException(org.pentaho.di.core.exception.KettleException)

Example 24 with StringBufferInputStream

use of java.io.StringBufferInputStream in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerJSP method doTimedComputePartitioningTest.

/**
 * Compute the partitions for the given filename using the default
 * partitioner for that file type.
 *
 * @param filename
 * @return int
 * @throws IOException
 * @throws BadLocationException
 */
protected int doTimedComputePartitioningTest(String filename) throws IOException, BadLocationException {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    InputStream inStream = getClass().getResourceAsStream(filename);
    if (inStream == null)
        inStream = new StringBufferInputStream("");
    IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (DEBUG_PRINT_RESULT && useFormatter) {
        double baseTen = Math.log(10);
        formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
        formatter.setGroupingUsed(false);
    }
    long startTime = System.currentTimeMillis();
    partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
    long endTime = System.currentTimeMillis();
    if (DEBUG_PRINT_RESULT) {
        String contents = null;
        System.out.println("\nfilename: " + filename);
        System.out.println("Time to compute " + partitions.length + ": " + (endTime - startTime) + " (msecs)");
        for (int i = 0; i < partitions.length; i++) {
            try {
                contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
            } catch (BadLocationException e) {
                contents = "*error*";
            }
            if (useFormatter)
                System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
            else
                System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
        }
    }
    checkSeams();
    model.releaseFromEdit();
    inStream.close();
    if (partitions == null)
        return -1;
    return partitions.length;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with StringBufferInputStream

use of java.io.StringBufferInputStream in project webtools.sourceediting by eclipse.

the class TestStructuredPartitionerJSP method doComputePartitioningTest.

/**
 * Compute the partitions for the given filename using the default
 * partitioner for that file type.
 *
 * @param filename
 * @return int
 * @throws IOException
 * @throws BadLocationException
 */
protected int doComputePartitioningTest(String filename) throws IOException, BadLocationException {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    InputStream inStream = getClass().getResourceAsStream(filename);
    if (inStream == null)
        inStream = new StringBufferInputStream("");
    IStructuredModel model = modelManager.getModelForEdit(filename, inStream, null);
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (DEBUG_PRINT_RESULT && useFormatter) {
        double baseTen = Math.log(10);
        formatter.setMinimumIntegerDigits((int) (Math.log(structuredDocument.getLength()) / baseTen) + 1);
        formatter.setGroupingUsed(false);
    }
    partitions = structuredDocument.computePartitioning(0, structuredDocument.getLength());
    if (DEBUG_PRINT_RESULT) {
        String contents = null;
        System.out.println("\nfilename: " + filename);
        for (int i = 0; i < partitions.length; i++) {
            try {
                contents = structuredDocument.get(partitions[i].getOffset(), partitions[i].getLength());
            } catch (BadLocationException e) {
                contents = "*error*";
            }
            if (useFormatter)
                System.out.println(formatter.format(partitions[i].getOffset()) + ":" + formatter.format(partitions[i].getLength()) + " - " + partitions[i].getType() + " [" + StringUtils.escape(contents) + "]");
            else
                System.out.println(partitions[i] + " [" + StringUtils.escape(contents) + "]");
        }
    }
    checkSeams();
    model.releaseFromEdit();
    inStream.close();
    if (partitions == null)
        return -1;
    return partitions.length;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

StringBufferInputStream (java.io.StringBufferInputStream)34 Test (org.junit.Test)10 InputStream (java.io.InputStream)9 SQLException (java.sql.SQLException)6 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)5 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 InputStreamBuilder (io.vertigo.dynamo.file.model.InputStreamBuilder)2 VFile (io.vertigo.dynamo.file.model.VFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Instant (java.time.Instant)2 Matchers.anyString (org.mockito.Matchers.anyString)2 KettleException (org.pentaho.di.core.exception.KettleException)2 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)2 Element (org.w3c.dom.Element)2 Table (com.mapr.db.Table)1 Description (io.qameta.allure.Description)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1