Package org.rssowl.core.connection.internal

Source Code of org.rssowl.core.connection.internal.FileProtocolHandler

/*   **********************************************************************  **
**   Copyright notice                                                       **
**                                                                          **
**   (c) 2005-2006 RSSOwl Development Team                                  **
**   http://www.rssowl.org/                                                 **
**                                                                          **
**   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.rssowl.org/legal/epl-v10.html                               **
**                                                                          **
**   A copy is found in the file epl-v10.html and important notices to the  **
**   license from the team is found in the textfile LICENSE.txt distributed **
**   in this package.                                                       **
**                                                                          **
**   This copyright notice MUST APPEAR in all copies of the file!           **
**                                                                          **
**   Contributors:                                                          **
**     RSSOwl Development Team - initial API and implementation             **
**                                                                          **
**  **********************************************************************  */

package org.rssowl.core.connection.internal;

import org.osgi.service.url.URLStreamHandlerService;
import org.rssowl.core.connection.ConnectionException;
import org.rssowl.core.connection.IProtocolHandler;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;

/**
* Handler for the FILE Protocol.
*
* @author bpasero
*/
public class FileProtocolHandler implements IProtocolHandler {

  /*
   * @see org.rssowl.core.connection.IProtocolHandler#load(java.net.URL)
   */
  public InputStream load(URL url) throws ConnectionException {
    return load(url, null);
  }

  /*
   * @see org.rssowl.core.connection.IProtocolHandler#load(java.net.URL,
   * java.util.Map)
   */
  public InputStream load(URL url, Map<Object, Object> properties) throws ConnectionException {
    try {
      File file = new File(url.toURI());
      return new BufferedInputStream(new FileInputStream(file));
    } catch (URISyntaxException e) {
      throw new ConnectionException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
    } catch (FileNotFoundException e) {
      throw new ConnectionException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
    }
  }

  /*
   * Do not override default URLStreamHandler of FILE and therefor return NULL.
   *
   * @see org.rssowl.core.connection.IProtocolHandler#getURLStreamHandler()
   */
  @SuppressWarnings("unused")
  public URLStreamHandlerService getURLStreamHandler() throws ConnectionException {
    return null;
  }
}
TOP

Related Classes of org.rssowl.core.connection.internal.FileProtocolHandler

TOP
Copyright © 2018 www.massapi.com. 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.