Example usage for java.io IOException IOException

List of usage examples for java.io IOException IOException

Introduction

In this page you can find the example usage for java.io IOException IOException.

Prototype

public IOException(Throwable cause) 

Source Link

Document

Constructs an IOException with the specified cause and a detail message of (cause==null ?

Usage

From source file:me.haohui.libhdfspp.NativeStatus.java

public void checkForIOException() throws IOException {
    if (!ok()) {//from   ww w. j a va2  s .co  m
        throw new IOException(new String(state, 8, state.length - 8, Charsets.UTF_8));
    }
}

From source file:ImageFrame.java

/**
 * Set the image from a file.//from  w  w w . ja v  a  2  s.  c  o m
 */
public void setImage(File file) throws IOException {
    // load the image
    Image image = getToolkit().getImage(file.getAbsolutePath());

    // wait for the image to entirely load
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);
    try {
        tracker.waitForID(0);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    if (tracker.statusID(0, true) != MediaTracker.COMPLETE) {
        throw new IOException("Could not load: " + file + " " + tracker.statusID(0, true));
    }

    setTitle(file.getName());
    setImage(image);
}

From source file:com.spstudio.common.image.ImageUtils.java

public static String zoom(String sourcePath, String targetPath, int width, int height) throws IOException {
    File imageFile = new File(sourcePath);
    if (!imageFile.exists()) {
        throw new IOException("Not found the images:" + sourcePath);
    }//from   ww  w.j a  va 2 s  .  c o m
    if (targetPath == null || targetPath.isEmpty()) {
        targetPath = sourcePath;
    }
    String format = sourcePath.substring(sourcePath.lastIndexOf(".") + 1, sourcePath.length());
    BufferedImage image = ImageIO.read(imageFile);
    image = zoom(image, width, height);
    ImageIO.write(image, format, new File(targetPath));
    return targetPath;
}

From source file:de.tudarmstadt.ukp.argumentation.data.roomfordebate.DataFetcher.java

/**
 * Crawls all URLs from the given list and stores them in the output folder; files that
 * already exist in the output folder are skipped
 *
 * @param urls      list of urls for Room for debate
 * @param outputDir output//w  w w . j a  va2 s .  co  m
 * @throws IOException ex
 */
public static void crawlPages(List<String> urls, File outputDir) throws IOException {
    for (String url : urls) {
        // file name
        File outFile = new File(outputDir, URLEncoder.encode(url, "utf-8") + ".html");

        if (!outFile.exists()) {
            NYTimesCommentsScraper nyTimesCommentsScraper = new NYTimesCommentsScraper();

            String html;
            try {
                html = nyTimesCommentsScraper.readHTML(url);
            } catch (InterruptedException e) {
                throw new IOException(e);
            }

            FileUtils.writeStringToFile(outFile, html);
        }
    }
}

From source file:gov.nih.nci.system.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor.java

protected HttpURLConnection openConnection(HttpInvokerClientConfiguration config) throws IOException {
    String url = config.getServiceUrl();
    if (url == null)
        throw new IOException("Service URL can not be empty");

    return super.openConnection(config);
}

From source file:net.hardisonbrewing.signingserver.service.SigStatusService.java

public static Hashtable downloadStatus() throws Exception {

    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(SigStatusInfo.URL);
    stringBuffer.append("?v=");
    stringBuffer.append(SigStatusInfo.VERSION);

    ConnectionFactory connectionFactory = new ConnectionFactory();
    connectionFactory.setAttemptsLimit(10);
    ConnectionDescriptor connectionDescriptor = connectionFactory.getConnection(stringBuffer.toString());

    if (connectionDescriptor == null) {
        SigservApplication.logEvent("Unable to obtain ConnectionDescriptor to download status");
        throw new IOException("Unable to obtain ConnectionDescriptor to download status");
    }/*from  w w  w .  j  av  a 2  s  .c o  m*/

    HttpConnection connection = null;
    InputStream inputStream = null;

    try {
        connection = (HttpConnection) connectionDescriptor.getConnection();
        inputStream = connection.openInputStream();
        return parse(inputStream);
    } finally {
        IOUtility.safeClose(inputStream);
        IOUtility.safeClose(connection);
    }
}

From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ThrowIOExceptionFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    throw new IOException("4_4 Error");
}

From source file:ch.entwine.weblounge.contentrepository.impl.index.elasticsearch.ElasticSearchUtils.java

/**
 * Creates an elastic search index configuration inside the given directory by
 * loading the relevant configuration files from the bundle. The final
 * location will be <code>homeDirectory/etc/index</code>.
 * //from ww  w  .ja  va2  s.  com
 * @param homeDirectory
 *          the configuration directory
 * @throws IOException
 *           if creating the configuration fails
 */
public static void createIndexConfigurationAt(File homeDirectory) throws IOException {

    // Load the index configuration and move it into place
    File configurationRoot = new File(PathUtils.concat(homeDirectory.getAbsolutePath(), "etc", "index"));
    FileUtils.deleteQuietly(configurationRoot);
    if (!configurationRoot.mkdirs())
        throw new IOException("Error creating " + configurationRoot);

    String[] files = new String[] { "default-mapping.json", "file-mapping.json", "image-mapping.json",
            "movie-mapping.json", "names.txt", "page-mapping.json", "settings.yml", "version-mapping.json" };

    for (String file : files) {
        String bundleLocation = UrlUtils.concat("/elasticsearch", file);
        File fileLocation = new File(configurationRoot, file);
        FileUtils.copyInputStreamToFile(ElasticSearchUtils.class.getResourceAsStream(bundleLocation),
                fileLocation);
    }

}

From source file:Main.java

/**
 * Compress a folder and its contents.//from   ww  w.j a  v a  2 s.c o  m
 * 
 * @param srcFolder path to the folder to be compressed.
 * @param destZipFile path to the final output zip file.
 * @param addBaseFolder flag to decide whether to add also the provided base folder or not.
 * @throws IOException 
 */
static public void zipFolder(String srcFolder, String destZipFile, boolean addBaseFolder) throws IOException {
    if (new File(srcFolder).isDirectory()) {

        ZipOutputStream zip = null;
        FileOutputStream fileWriter = null;
        try {
            fileWriter = new FileOutputStream(destZipFile);
            zip = new ZipOutputStream(fileWriter);
            addFolderToZip("", srcFolder, zip, addBaseFolder); //$NON-NLS-1$
        } finally {
            if (zip != null) {
                zip.flush();
                zip.close();
            }
            if (fileWriter != null)
                fileWriter.close();
        }
    } else {
        throw new IOException(srcFolder + " is not a folder.");
    }
}

From source file:de.tudarmstadt.ukp.dkpro.c4corpus.boilerplate.impl.Utils.java

/**
 * Loads the stop-words list of a given language
 *
 * @param locale locale//from  w ww.ja va 2 s  .  c om
 * @return set of stop words
 * @throws IOException exception
 */
public static Set<String> loadStopWords(Locale locale) throws IOException {

    String streamName = "/stoplists/" + locale.getLanguage() + ".txt";
    InputStream stream = Utils.class.getResourceAsStream(streamName);

    if (stream == null) {
        throw new IOException("Stream " + streamName + " not found");
    }

    List<String> stopList = IOUtils.readLines(stream);
    return new HashSet<>(stopList);

}