Search in sources :

Example 1 with ResourceDownloaderFactoryImpl

use of com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl in project BiglyBT by BiglySoftware.

the class PairingManagerImpl method listGroup.

@Override
public List<PairedNode> listGroup() throws PairingException {
    try {
        URL url = new URL(SERVICE_URL + "/remote/listGroup?gc=" + getGroup());
        InputStream is = new ResourceDownloaderFactoryImpl().create(url).download();
        Map json = JSONUtils.decodeJSON(new String(FileUtil.readInputStreamAsByteArray(is), "UTF-8"));
        List<Map> list = (List<Map>) json.get("result");
        List<PairedNode> result = new ArrayList<>();
        String my_ac = peekAccessCode();
        if (list != null) {
            for (Map m : list) {
                PairedNodeImpl node = new PairedNodeImpl(m);
                if (my_ac == null || !my_ac.equals(node.getAccessCode())) {
                    result.add(node);
                }
            }
        }
        return (result);
    } catch (Throwable e) {
        throw (new PairingException("Failed to list group", e));
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ResourceDownloaderFactoryImpl(com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)

Example 2 with ResourceDownloaderFactoryImpl

use of com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl in project BiglyBT by BiglySoftware.

the class PairingManagerImpl method lookupServices.

@Override
public List<PairedService> lookupServices(String access_code) throws PairingException {
    try {
        URL url = new URL(SERVICE_URL + "/remote/listBindings?ac=" + access_code + "&jsoncallback=");
        InputStream is = new ResourceDownloaderFactoryImpl().create(url).download();
        String reply = new String(FileUtil.readInputStreamAsByteArray(is), "UTF-8");
        // hack to remove callback
        reply = reply.substring(1, reply.length() - 1);
        Map json = JSONUtils.decodeJSON(reply);
        Map error = (Map) json.get("error");
        if (error != null) {
            throw (new PairingException((String) error.get("msg")));
        }
        List<Map> list = (List<Map>) json.get("result");
        List<PairedService> result = new ArrayList<>();
        if (list != null) {
            for (Map m : list) {
                result.add(new PairedService2Impl((String) m.get("sid"), m));
            }
        }
        return (result);
    } catch (Throwable e) {
        throw (new PairingException("Failed to lookup services", e));
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ResourceDownloaderFactoryImpl(com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)

Example 3 with ResourceDownloaderFactoryImpl

use of com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl in project BiglyBT by BiglySoftware.

the class TorrentUtils method download.

public static TOTorrent download(URL url, long timeout) throws IOException {
    try {
        PluginProxy plugin_proxy = null;
        try {
            if (AENetworkClassifier.categoriseAddress(url.getHost()) != AENetworkClassifier.AT_PUBLIC) {
                plugin_proxy = AEProxyFactory.getPluginProxy("torrent download", url);
            }
            ResourceDownloader rd;
            if (plugin_proxy == null) {
                rd = new ResourceDownloaderFactoryImpl().create(url);
            } else {
                rd = new ResourceDownloaderFactoryImpl().create(plugin_proxy.getURL(), plugin_proxy.getProxy());
                rd.setProperty("URL_HOST", url.getHost());
            }
            if (timeout > 0) {
                rd.setProperty("URL_Connect_Timeout", timeout);
                rd.setProperty("URL_Read_Timeout", timeout);
            }
            byte[] bytes = FileUtil.readInputStreamAsByteArray(rd.download(), BDecoder.MAX_BYTE_ARRAY_SIZE);
            return (TOTorrentFactory.deserialiseFromBEncodedByteArray(bytes));
        } finally {
            if (plugin_proxy != null) {
                plugin_proxy.setOK(true);
            }
        }
    } catch (IOException e) {
        throw ((IOException) e);
    } catch (Throwable e) {
        throw (new IOException(Debug.getNestedExceptionMessage(e)));
    }
}
Also used : PluginProxy(com.biglybt.core.proxy.AEProxyFactory.PluginProxy) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) ResourceDownloaderFactoryImpl(com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)

Example 4 with ResourceDownloaderFactoryImpl

use of com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl in project BiglyBT by BiglySoftware.

the class UPNPMSBrowserImpl method getXML.

private SimpleXMLParserDocument getXML(URL url, String soap_action, String post_data) throws UPnPMSException {
    ResourceDownloader rd = new ResourceDownloaderFactoryImpl().create(url, post_data);
    try {
        rd.setProperty("URL_Connection", "Keep-Alive");
        rd.setProperty("URL_Read_Timeout", 10 * 60 * 1000);
        rd.setProperty("URL_Connect_Timeout", 5 * 60 * 1000);
        rd.setProperty("URL_SOAPAction", "\"" + soap_action + "\"");
        rd.setProperty("URL_X-AV-Client-Info", "av=1.0; cn=\"" + Constants.AZUREUS_NAME + "\"; mn=\"" + client_name + "\"; mv=\"" + Constants.AZUREUS_VERSION + "\"");
        rd.setProperty("URL_Content-Type", "text/xml; charset=\"utf-8\"");
        SimpleXMLParserDocument doc = SimpleXMLParserDocumentFactory.create(url, rd.download());
        return (doc);
    } catch (Throwable e) {
        throw (new UPnPMSException("XML RPC failed", e));
    }
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument) UPnPMSException(com.biglybt.net.upnpms.UPnPMSException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) ResourceDownloaderFactoryImpl(com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)

Aggregations

ResourceDownloaderFactoryImpl (com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)4 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 PluginProxy (com.biglybt.core.proxy.AEProxyFactory.PluginProxy)1 UPnPMSException (com.biglybt.net.upnpms.UPnPMSException)1 SimpleXMLParserDocument (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument)1