blob: 2a82a1f529b75fbbc0122b173bb5e4c53a77a5a9 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009, 2017 xored software, Inc. 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
*
* Contributors:
* xored software, Inc. - initial API and Implementation (Alex Panchenko)
*******************************************************************************/
package org.eclipse.dltk.ui.documentation;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
/**
* @since 2.0
*/
public class DocumentationFileResponse extends AbstractDocumentationResponse {
private final File file;
private final String encoding;
/**
* @param file
* @param encoding
*/
public DocumentationFileResponse(Object object, File file) {
this(object, file, null);
}
/**
* @param file
* @param encoding
*/
public DocumentationFileResponse(Object object, File file, String encoding) {
super(object);
this.file = file;
this.encoding = encoding;
}
@Override
public Reader getReader() throws FileNotFoundException,
UnsupportedEncodingException {
final InputStream stream = new FileInputStream(file);
return encoding != null ? new InputStreamReader(stream, encoding)
: new InputStreamReader(stream);
}
@Override
public URL getURL() throws MalformedURLException {
return file.toURI().toURL();
}
}