java.net.URLConnection#setAllowUserInteraction ( )源码实例Demo

下面列出了java.net.URLConnection#setAllowUserInteraction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: IridiumSkyblock   文件: IridiumSkyblock.java
public void downloadConfig(String language, File file) {
    getLogger().info("https://iridiumllc.com/Languages/" + language + "/" + file.getName());
    try {
        URLConnection connection = new URL("https://iridiumllc.com/Languages/" + language + "/" + file.getName()).openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
        connection.setAllowUserInteraction(false);
        connection.setDoOutput(true);
        InputStream in = connection.getInputStream();

        if (!file.exists()) file.createNewFile();
        OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        byte[] buffer = new byte[1024];

        int numRead;
        while ((numRead = in.read(buffer)) != -1) {
            out.write(buffer, 0, numRead);
        }
        in.close();
        out.close();
    } catch (IOException e) {
        IridiumSkyblock.getInstance().getLogger().info("Failed to connect to Translation servers");
    }
}
 
源代码2 项目: shortyz   文件: PuzzleDownloadListener.java
private InputStream OpenHttpConnection(URL url, String cookies)
    throws IOException {
    InputStream in = null;
    URLConnection conn = url.openConnection();

    if ((cookies != null) && !cookies.trim()
                                         .equals("")) {
        conn.setRequestProperty("Cookie", cookies);
    }

    conn.setAllowUserInteraction(false);
    conn.connect();
    in = conn.getInputStream();

    return in;
}
 
源代码3 项目: pentaho-reporting   文件: URLResourceData.java
private void readMetaData() throws IOException {
  if ( metaDataOK ) {
    if ( ( System.currentTimeMillis() - lastDateMetaDataRead ) < URLResourceData.getFixedCacheDelay() ) {
      return;
    }
    if ( isFixBrokenWebServiceDateHeader() ) {
      return;
    }

  }

  final URLConnection c = url.openConnection();
  c.setDoOutput( false );
  c.setAllowUserInteraction( false );
  if ( c instanceof HttpURLConnection ) {
    final HttpURLConnection httpURLConnection = (HttpURLConnection) c;
    httpURLConnection.setRequestMethod( "HEAD" );
  }
  c.connect();
  readMetaData( c );
  c.getInputStream().close();
}
 
源代码4 项目: smslib-v3   文件: Http.java
List<String> HttpPost(URL url) throws IOException
{
	List<String> responseList = new ArrayList<String>();
	URL cleanUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
	Logger.getInstance().logInfo("HTTP POST: " + cleanUrl, null, null);
	URLConnection con = cleanUrl.openConnection();
	con.setDoOutput(true);
	OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
	out.write(url.getQuery());
	out.flush();
	con.setAllowUserInteraction(false);
	BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
	String inputLine;
	while ((inputLine = in.readLine()) != null)
		responseList.add(inputLine);
	out.close();
	in.close();
	return responseList;
}
 
源代码5 项目: FxDock   文件: WebReader.java
public byte[] readBytes(URL url) throws Exception
	{
		URLConnection c = url.openConnection();
		
//		if(c instanceof HttpsURLConnection)
//		{
//			// TODO set gullible access handler?
//		}
		
		c.setConnectTimeout(connectTimeout);
		c.setReadTimeout(readTimeout);
		c.setDoOutput(false);
		c.setAllowUserInteraction(false);
		c.setUseCaches(false);
		
		c.connect();
		
		//D.print("content-encoding: " + c.getContentEncoding());
		
		// text/html
		// image/jpeg
		// text/plain
		//D.print("content-type: " + c.getContentType());
		
		InputStream in = c.getInputStream();
		try
		{
			return CKit.readBytes(in, maxContentLength);
		}
		finally
		{
			CKit.close(in);
		}
	}
 
源代码6 项目: groovy   文件: ResourceGroovyMethods.java
/**
 * Creates an inputstream for this URL, with the possibility to set different connection parameters using the
 * <i>parameters map</i>:
 * <ul>
 * <li>connectTimeout : the connection timeout</li>
 * <li>readTimeout : the read timeout</li>
 * <li>useCaches : set the use cache property for the URL connection</li>
 * <li>allowUserInteraction : set the user interaction flag for the URL connection</li>
 * <li>requestProperties : a map of properties to be passed to the URL connection</li>
 * </ul>
 *
 * @param parameters an optional map specifying part or all of supported connection parameters
 * @param url        the url for which to create the inputstream
 * @return an InputStream from the underlying URLConnection
 * @throws IOException if an I/O error occurs while creating the input stream
 * @since 1.8.1
 */
private static InputStream configuredInputStream(Map parameters, URL url) throws IOException {
    final URLConnection connection = url.openConnection();
    if (parameters != null) {
        if (parameters.containsKey("connectTimeout")) {
            connection.setConnectTimeout(DefaultGroovyMethods.asType(parameters.get("connectTimeout"), Integer.class));
        }
        if (parameters.containsKey("readTimeout")) {
            connection.setReadTimeout(DefaultGroovyMethods.asType(parameters.get("readTimeout"), Integer.class));
        }
        if (parameters.containsKey("useCaches")) {
            connection.setUseCaches(DefaultGroovyMethods.asType(parameters.get("useCaches"), Boolean.class));
        }
        if (parameters.containsKey("allowUserInteraction")) {
            connection.setAllowUserInteraction(DefaultGroovyMethods.asType(parameters.get("allowUserInteraction"), Boolean.class));
        }
        if (parameters.containsKey("requestProperties")) {
            @SuppressWarnings("unchecked")
            Map<String, CharSequence> properties = (Map<String, CharSequence>) parameters.get("requestProperties");
            for (Map.Entry<String, CharSequence> entry : properties.entrySet()) {
                connection.setRequestProperty(entry.getKey(), entry.getValue().toString());
            }
        }

    }
    return connection.getInputStream();
}
 
源代码7 项目: pentaho-reporting   文件: URLResourceData.java
public InputStream getResourceAsStream( final ResourceManager caller ) throws ResourceLoadingException {
  try {
    final URLConnection c = url.openConnection();
    c.setDoOutput( false );
    c.setAllowUserInteraction( false );
    c.connect();
    if ( isFixBrokenWebServiceDateHeader() == false ) {
      readMetaData( c );
    }
    return c.getInputStream();
  } catch ( IOException e ) {
    throw new ResourceLoadingException( "Failed to open URL connection", e );
  }
}
 
源代码8 项目: smslib-v3   文件: Http.java
List<String> HttpGet(URL url) throws IOException
{
	List<String> responseList = new ArrayList<String>();
	Logger.getInstance().logInfo("HTTP GET: " + url, null, null);
	URLConnection con = url.openConnection();
	con.setAllowUserInteraction(false);
	BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
	String inputLine;
	while ((inputLine = in.readLine()) != null)
		responseList.add(inputLine);
	in.close();
	return responseList;
}
 
源代码9 项目: smslib-v3   文件: HTTPGateway.java
List<String> HttpGet(URL url) throws IOException
{
	List<String> responseList = new ArrayList<String>();
	Logger.getInstance().logInfo("HTTP GET: " + url, null, getGatewayId());
	URLConnection con = url.openConnection();
	con.setConnectTimeout(20000);
	con.setAllowUserInteraction(false);
	BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
	String inputLine;
	while ((inputLine = in.readLine()) != null)
		responseList.add(inputLine);
	in.close();
	return responseList;
}