Here you can find the source of isValidToc(URL url)
private static boolean isValidToc(URL url)
//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); } }