Package com.salas.bb.utils.net

Examples of com.salas.bb.utils.net.URLInputStream


        throws UrlDiscovererException
    {
        boolean detected = false;

        RedirectionListener listener = new RedirectionListener(source);
        URLInputStream uis = null;
        try
        {
            uis = new URLInputStream(source, System.getProperty("http.agent.discoverer"));
            uis.setRedirectionListener(listener);

            XMLFormatDetector detector = new XMLFormatDetector();
            XMLFormat fmt = detector.detect(uis);

            detected = fmt != null && fmt != XMLFormat.OPML;
        } catch (IOException e)
        {
            throw new UrlDiscovererException(e);
        } finally
        {
            try
            {
                if (uis != null) uis.close();
            } catch (IOException e)
            {
                // No problems. Just trying to be nice.
            }
        }
View Full Code Here


     * @throws java.io.IOException in case of I/O error.
     */
    public XMLFormat detect(URL url)
        throws IOException
    {
        return detect(new URLInputStream(url));
    }
View Full Code Here

    protected void processLoad()
        throws IOException
    {
        // Read data from URL into buffer
        StringBuffer sb = new StringBuffer();
        BufferedInputStream stream = new BufferedInputStream(new URLInputStream(resourceUrl));
        int next;
        while ((next = stream.read()) != -1)
        {
            sb.append((char)next);
        }
View Full Code Here

        builder.setEntityResolver(EmptyEntityResolver.INSTANCE);

        Document doc;
        try
        {
            doc = builder.build(XmlReaderFactory.create(new URLInputStream(url)));
        } catch (Exception e)
        {
            LOG.log(Level.SEVERE, MessageFormat.format(Strings.error("there.was.a.problem.reading.a.collection.0"), new Object[] { url }), e);
            throw new LoaderException(Strings.error("there.was.a.problem.reading.a.collection"));
        }
View Full Code Here

        InputStream inp;

        if (file == null)
        {
            // Create from URL
            URLInputStream in = new URLInputStream(url);
            netTask = NetManager.register(NetManager.TYPE_ARTICLE_IMAGE, url.toString(), "", in);
            inp = in;
        } else
        {
            // Create from local file
View Full Code Here

            password = matcher.group(3);
            xmlURL = new URL(matcher.group(1) + matcher.group(4));
        }

        // Create stream for reading the feed and register it
        URLInputStream stream = new URLInputStream(xmlURL, lastUpdateTime);
        stream.setBasicAuthenticationInfo(username, password);
        if (title == null) title = xmlURL.toString();
        NetManager.register(NetManager.TYPE_POLLING, title, title, stream);
        stream.setRedirectionListener(new RomeFeedParser.RedirectionRecorder(result));

        stream.connect();
        try
        {
            long lastModifiedTime = stream.getLastModifiedTime();
            if (lastModifiedTime == -1) lastModifiedTime = stream.getServerTime();

            if (stream.getResponseCode() != HttpURLConnection.HTTP_NOT_MODIFIED)
            {
                result = parse(stream, result, xmlURL);
            }

            Channel channel = result.getChannel();
            if (channel != null) channel.setLastUpdateServerTime(lastModifiedTime);
        } finally
        {
            stream.close();
        }

        return result;
    }
View Full Code Here

    /**
     * Tests creation of task.
     */
    public void testCreationTask()
    {
        URLInputStream stream = new URLInputStream(getTestURL());
        long time = System.currentTimeMillis();

        NetTask task = new NetTask("A", "B", stream);
        long startTime = task.getStartTime().getTime();

        assertEquals("B", task.getFeed());
        assertNull(task.getParent());
        assertEquals(-1, (int)task.getProgress());
        assertEquals(-1, task.getSize());
        assertTrue(stream.getSourceURL() == task.getSourceURL());
        assertTrue(startTime >= time && startTime <= time + 20);
        assertEquals(NetTask.STATUS_CONNECTING, task.getStatus());
        assertEquals("A", task.getTitle());

        assertEquals("A", task.toString());
View Full Code Here

    /**
     * Test the chaning of status during operations.
     */
    public void testSetStatus() throws InterruptedException
    {
        NetTask task = new NetTask("A", "B", new URLInputStream(getTestURL()));
        RecordingPropertyChangeListener recorder = new RecordingPropertyChangeListener();

        task.addPropertyChangeListener(recorder);
        task.pause();
        int status = task.getStatus();
View Full Code Here

     * Test the changing of paused status of the stream in response to operations over the task.
     */
    public void testStreamPaused()
        throws InterruptedException
    {
        URLInputStream stream = new URLInputStream(getTestURL());
        NetTask task = new NetTask("A", "B", stream);

        assertFalse(stream.isPaused());
        task.pause();

        // We need to sleep a bit before the check as the operation of pausing / unpausing
        // is async and takes a while to finish.
        Thread.sleep(100);

        assertTrue(stream.isPaused());
        task.resume();

        // We need to sleep a bit before the check as the operation of pausing / unpausing
        // is async and takes a while to finish.
        Thread.sleep(100);

        assertFalse(stream.isPaused());
        task.abort();
        assertFalse(stream.isPaused());
        assertTrue(stream.isClosed());
    }
View Full Code Here

     * Tests adding of tasks.
     */
    public void testAddTask()
    {
        NetTaskGroup group = new NetTaskGroup("A");
        NetTask task = new NetTask("A", "B", new URLInputStream(getTestURL()));

        group.addTask(task);

        assertTrue(task.getParent() == group);
        assertEquals(1, group.getTaskCount());
View Full Code Here

TOP

Related Classes of com.salas.bb.utils.net.URLInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.