Java URL Connection isValidToc(URL url)

Here you can find the source of isValidToc(URL url)

Description

is Valid Toc

License

Open Source License

Declaration

private static boolean isValidToc(URL url) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /* w w  w .j a v a 2s .  c  om*/
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    private final static int SOCKET_TIMEOUT = 5000;

    private static boolean isValidToc(URL url) {
        InputStream in = null;
        try {
            URLConnection connection = url.openConnection();
            setTimeout(connection, SOCKET_TIMEOUT);
            connection.connect();
            in = connection.getInputStream();
            if (in != null) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                String line;
                while ((line = reader.readLine()) != null) {
                    if (line.indexOf("<tocContributions>") > -1) { //$NON-NLS-1$
                        reader.close();
                        return true;
                    }
                }
                reader.close();
            }
        } catch (Exception ex) {
        } finally {
            try {
                if (in != null)
                    in.close();
            } catch (IOException e) {
            }
        }
        return false;
    }

    private static void setTimeout(URLConnection conn, int milliseconds) {
        conn.setConnectTimeout(milliseconds);
    }
}

Related

  1. httpPost(String urlString, String postPath, Map keyValuePairs)
  2. imageFromUrl(String url)
  3. isJarDirectory(JarURLConnection conn)
  4. isOnline(String url)
  5. isUrlReachable(String url)
  6. isValidUrl(String input)
  7. isZipName(URI documentIRI, URLConnection connection)
  8. jarURLDirectories(URL jarURL)
  9. jarURLEntryResource(String jarURLString)