org.eclipse.jetty.util.IO Java Examples

The following examples show how to use org.eclipse.jetty.util.IO. 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 File: JarResource.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
@Override
public InputStream getInputStream()
    throws java.io.IOException
{     
    checkConnection();
    if (!_urlString.endsWith("!/"))
        return new FilterInputStream(super.getInputStream()) 
        {
            @Override
            public void close() throws IOException {this.in=IO.getClosedStream();}
        };

    URL url = new URL(_urlString.substring(4,_urlString.length()-2));      
    InputStream is = url.openStream();
    return is;
}
 
Example #2
Source File: Resource.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/** 
 * @param out 
 * @param start First byte to write
 * @param count Bytes to write or -1 for all of them.
 */
public void writeTo(OutputStream out,long start,long count)
    throws IOException
{
    InputStream in = getInputStream();
    try
    {
        in.skip(start);
        if (count<0)
            IO.copy(in,out);
        else
            IO.copy(in,out,count);
    }
    finally
    {
        in.close();
    }
}
 
Example #3
Source File: JarResource.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
@Override
public InputStream getInputStream()
    throws java.io.IOException
{     
    checkConnection();
    if (!_urlString.endsWith("!/"))
        return new FilterInputStream(super.getInputStream()) 
        {
            @Override
            public void close() throws IOException {this.in=IO.getClosedStream();}
        };

    URL url = new URL(_urlString.substring(4,_urlString.length()-2));      
    InputStream is = url.openStream();
    return is;
}
 
Example #4
Source File: Resource.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/** 
 * @param out 
 * @param start First byte to write
 * @param count Bytes to write or -1 for all of them.
 */
public void writeTo(OutputStream out,long start,long count)
    throws IOException
{
    InputStream in = getInputStream();
    try
    {
        in.skip(start);
        if (count<0)
            IO.copy(in,out);
        else
            IO.copy(in,out,count);
    }
    finally
    {
        in.close();
    }
}
 
Example #5
Source File: HostedRepositoryIntegrationTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
private String getResponse(URI uri) throws IOException {
    HttpURLConnection http = (HttpURLConnection) uri.toURL().openConnection();
    assertThat("Valid Response Code",
               http.getResponseCode(),
               anyOf(is(200),
                     is(404)));

    try (InputStream in = http.getInputStream()) {
        return IO.toString(in,
                           StandardCharsets.UTF_8);
    }
}
 
Example #6
Source File: FileResource.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
@Override
public void copyTo(File destination)
    throws IOException
{
    if (isDirectory())
    {
        IO.copyDir(getFile(),destination);
    }
    else
    {
        if (destination.exists())
            throw new IllegalArgumentException(destination+" exists");
        IO.copy(getFile(),destination);
    }
}
 
Example #7
Source File: FileResource.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
@Override
public void copyTo(File destination)
    throws IOException
{
    if (isDirectory())
    {
        IO.copyDir(getFile(),destination);
    }
    else
    {
        if (destination.exists())
            throw new IllegalArgumentException(destination+" exists");
        IO.copy(getFile(),destination);
    }
}
 
Example #8
Source File: Files.java    From chipster with MIT License 5 votes vote down vote up
public static byte[] inputStreamToBytes(InputStream input, long byteCount) throws IOException  {
	if (input == null) {
		throw new NullPointerException("parameter input is null.");
	}
	
	BufferedInputStream in = new BufferedInputStream(input);
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	if (byteCount == -1) {
		IO.copy(in, out);
	} else {
		IO.copy(in, out, byteCount);
	}
	return out.toByteArray();
}
 
Example #9
Source File: Log.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public Object run()
{
    /* First see if the jetty-logging.properties object exists in the classpath.
     * This is an optional feature used by embedded mode use, and test cases to allow for early
     * configuration of the Log class in situations where access to the System.properties are
     * either too late or just impossible.
     */
    URL testProps = Loader.getResource(Log.class,"jetty-logging.properties",true);
    if (testProps != null)
    {
        InputStream in = null;
        try
        {
            in = testProps.openStream();
            __props.load(in);
        }
        catch (IOException e)
        {
            System.err.println("Unable to load " + testProps);
            e.printStackTrace(System.err);
        }
        finally
        {
            IO.close(in);
        }
    }

    /* Now load the System.properties as-is into the __props, these values will override
     * any key conflicts in __props.
     */
    @SuppressWarnings("unchecked")
    Enumeration<String> systemKeyEnum = (Enumeration<String>)System.getProperties().propertyNames();
    while (systemKeyEnum.hasMoreElements())
    {
        String key = systemKeyEnum.nextElement();
        String val = System.getProperty(key);
        //protect against application code insertion of non-String values (returned as null)
        if (val != null)
            __props.setProperty(key,val);
    }

    /* Now use the configuration properties to configure the Log statics
     */
    __logClass = __props.getProperty("org.eclipse.jetty.util.log.class","org.eclipse.jetty.util.log.Slf4jLog");
    __ignored = Boolean.parseBoolean(__props.getProperty("org.eclipse.jetty.util.log.IGNORED","false"));
    return null;
}
 
Example #10
Source File: Log.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
public Object run()
{
    /* First see if the jetty-logging.properties object exists in the classpath.
     * This is an optional feature used by embedded mode use, and test cases to allow for early
     * configuration of the Log class in situations where access to the System.properties are
     * either too late or just impossible.
     */
    URL testProps = Loader.getResource(Log.class,"jetty-logging.properties",true);
    if (testProps != null)
    {
        InputStream in = null;
        try
        {
            in = testProps.openStream();
            __props.load(in);
        }
        catch (IOException e)
        {
            System.err.println("Unable to load " + testProps);
            e.printStackTrace(System.err);
        }
        finally
        {
            IO.close(in);
        }
    }

    /* Now load the System.properties as-is into the __props, these values will override
     * any key conflicts in __props.
     */
    @SuppressWarnings("unchecked")
    Enumeration<String> systemKeyEnum = (Enumeration<String>)System.getProperties().propertyNames();
    while (systemKeyEnum.hasMoreElements())
    {
        String key = systemKeyEnum.nextElement();
        String val = System.getProperty(key);
        //protect against application code insertion of non-String values (returned as null)
        if (val != null)
            __props.setProperty(key,val);
    }

    /* Now use the configuration properties to configure the Log statics
     */
    __logClass = __props.getProperty("org.eclipse.jetty.util.log.class","org.eclipse.jetty.util.log.Slf4jLog");
    __ignored = Boolean.parseBoolean(__props.getProperty("org.eclipse.jetty.util.log.IGNORED","false"));
    return null;
}
 
Example #11
Source File: TestMultiTenancyAPI.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void testEOFStreams() throws IOException {
	final InputStream closed = IO.getClosedStream();
	
	assertTrue(closed.read() == -1);
}
 
Example #12
Source File: RequestHandler.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public void handle(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    jettyRequest.setHandled(true);
    response.setContentType(request.getContentType());
    IO.copy(request.getInputStream(), response.getOutputStream());
}
 
Example #13
Source File: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @deprecated use {@link #parse(Reader)}
 * @param in
 *            Reader containing JSON object or array.
 * @return A Map, Object array or primitive array parsed from the JSON.
 */
@Deprecated
public static Object parse(InputStream in) throws IOException
{
    return DEFAULT.parse(new StringSource(IO.toString(in)),false);
}
 
Example #14
Source File: JSON.java    From cmake4eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * @deprecated use {@link #parse(Reader, boolean)}
 * @param in
 *            Stream containing JSON object or array.
 * @param stripOuterComment
 *            If true, an outer comment around the JSON is ignored.
 * @return A Map, Object array or primitive array parsed from the JSON.
 */
@Deprecated
public static Object parse(InputStream in, boolean stripOuterComment) throws IOException
{
    return DEFAULT.parse(new StringSource(IO.toString(in)),stripOuterComment);
}