Example usage for java.io IOException getCause

List of usage examples for java.io IOException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.amazonaws.hbase.kinesis.utils.HBaseUtils.java

/**
 * Helper method to create an HBase table in an Amazon EMR cluster with HBase installed
 * /*from w  ww  .jav a  2  s .c o m*/
 * @param tableName - name for table to create
 * @param dnsId - Amazon EMR master node public DNS
 * @param hbaseRestPort - HBase Rest port
 */
public static void createTable(String tableName, String dnsId, int hbaseRestPort) {
    Configuration config = HBaseConfiguration.create();
    RemoteAdmin admin = new RemoteAdmin(new Client(new Cluster().add(dnsId, hbaseRestPort)), config);
    String[] families = { "user", "address", "contact", "likes" };
    try {
        if (admin.isTableAvailable(tableName)) {
            LOG.info("table already exists!");
            return;
        } else {
            HTableDescriptor tableDesc = new HTableDescriptor(tableName);
            for (int i = 0; i < families.length; i++) {
                tableDesc.addFamily(new HColumnDescriptor(families[i]));
            }
            admin.createTable(tableDesc);
            isTableAvailable = true;
            LOG.info("create table " + tableName + " ok.");
        }

    } catch (IOException e) {
        LOG.error(e, e.getCause());
    }

}

From source file:com.amazonaws.hbase.kinesis.utils.HBaseUtils.java

/**
 * Helper method to insert a Record into HBase
 * // w w w .  j  a v  a2 s.  com
 * @param tableName - table to insert records
 * @param dnsId - Amazon EMR master node public DNS
 * @param hbaseRestPort -  HBase Rest port
 * @param rowKey - row unique identifier
 * @param family - column family name
 * @param qualifier - column qualifier
 * @param value - value for this key pair
 */
public static void addRecord(String tableName, String dnsId, int hbaseRestPort, String rowKey, String family,
        String qualifier, String value) {
    RemoteHTable table = null;
    try {
        table = new RemoteHTable(new Client(new Cluster().add(dnsId, hbaseRestPort)), tableName);
        if (isTableAvailable) {
            Put put = new Put(Bytes.toBytes(rowKey));
            put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
            table.put(put);
            table.flushCommits();
            LOG.info("insert recored " + rowKey + " to table " + tableName + " ok.");
        } else
            createTable(tableName, dnsId, hbaseRestPort);
    } catch (IOException e) {
        LOG.error(e, e.getCause());
        if (table != null) {
            try {
                table.close();
            } catch (IOException e1) {
                LOG.error(e, e.getCause());
            }
        }
    }
}

From source file:com.amazonaws.hbase.kinesis.utils.HBaseUtils.java

/**
 * Helper method that checks if a table exists in HBase
 * /* w ww .j  a  va2  s  .  co m*/
 * @param tableName - table to check
 * @param dnsId - Amazon EMR master node public DNS
 * @param hbaseRestPort - HBase Rest port
 * @return
 */
public static boolean tablesExists(String tableName, String dnsId, int hbaseRestPort) {
    Configuration config = HBaseConfiguration.create();
    RemoteAdmin admin = new RemoteAdmin(new Client(new Cluster().add(dnsId, hbaseRestPort)), config);
    try {
        if (admin.isTableAvailable(tableName)) {
            LOG.info("table already exists!");
            System.out.println("table already exists!");
            return true;
        }

    } catch (IOException e) {
        e.printStackTrace();
        LOG.error(e, e.getCause());
    }
    return false;
}

From source file:facturatron.facturacion.PAC.finkok.ClassicKeyLoader.java

/**
 * @param crtInputStream    Flujo de entrada del certificado del cual se obtiene la llave privada
 * @param passwd            Contrasea con la cual se puede obtener la informacin de la llave
 *                          privada//from  w w  w.j a  v a2  s  .  c o  m
 *
 * @return  Llave privada encapsulada en el objeto {@link PrivateKey}
 *
 * @throws KeyException Lanzada si existe un problema con la lectura de la llave privada. La
 *                      excepcin es lanzada si alguno de estos casos se presenta:
 *                      <ul>
 *                          <li>
 *                              Error de lectura del flujo de entrada del documento.
 *                          </li>
 *                          <li>
 *                              Error en la obtencn de la informacin de la llave privada debido
 *                              a que la contrasea no es correcta.
 *                          </li>
 *                          <li>
 *                              Error en la obtencin de la llave privada debido a que el algoritmo
 *                              de cifrado no es el adecuado para el certificado.
 *                          </li>
 *                      </ul>
 */
public static PrivateKey loadPKCS8PrivateKey(InputStream crtInputStream, String passwd) throws KeyException {
    byte[] decrypted = null;
    PrivateKey privateKey = null;

    try {
        decrypted = (passwd != null) ? getCertBytes(crtInputStream, passwd.toCharArray())
                : getBytes(crtInputStream);
    } catch (IOException ioe) {
        throw new KeyException("Error de E/S al leer la informacin del certificado", ioe.getCause());
    }

    PKCS8EncodedKeySpec keysp = new PKCS8EncodedKeySpec(decrypted);

    try {
        KeyFactory kf = KeyFactory.getInstance("RSA");
        privateKey = kf.generatePrivate(keysp);
    } catch (GeneralSecurityException gse) {
        throw new KeyException("Error al obtener la informacin del certificado debido a su codificacin",
                gse.getCause());
    }

    return privateKey;
}

From source file:com.simiacryptus.util.test.Shakespeare.java

private static void read() {
    try {//  ww  w.  j ava  2  s  . c o  m
        InputStream in = Util.cache(url, file);
        String txt = new String(IOUtils.toByteArray(in), "UTF-8").replaceAll("\r", "");
        for (String paragraph : txt.split("\n\\s*\n")) {
            queue.add(new Shakespeare(paragraph));
        }
    } catch (final IOException e) {
        // Ignore... end of stream
    } catch (final RuntimeException e) {
        if (!(e.getCause() instanceof InterruptedException))
            throw e;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.simiacryptus.util.test.EnglishWords.java

private static void read() {
    try {//  ww w.  j a  v a  2  s  .co m
        InputStream in = Util.cache(url, file);
        String txt = new String(IOUtils.toByteArray(in), "UTF-8").replaceAll("\r", "");
        List<String> list = Arrays.stream(txt.split("\n")).map(x -> x.replaceAll("[^\\w]", ""))
                .collect(Collectors.toList());
        Collections.shuffle(list);
        for (String paragraph : list) {
            queue.add(new EnglishWords(paragraph));
        }
    } catch (final IOException e) {
        // Ignore... end of stream
    } catch (final RuntimeException e) {
        if (!(e.getCause() instanceof InterruptedException))
            throw e;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:fr.paris.lutece.plugins.seo.service.sitemap.SitemapService.java

/**
 * Generate Sitemap//from   w  w w .j a va2s. co m
 * @return The sitemap content
 */
public static String generateSitemap() {
    List<FriendlyUrl> list = getSitemapUrls();
    Map<String, Object> model = new HashMap<String, Object>();

    model.put(MARK_URLS_LIST, list);

    HtmlTemplate templateList = AppTemplateService.getTemplate(TEMPLATE_SITEMAP_XML, Locale.getDefault(),
            model);

    String strXmlSitemap = templateList.getHtml();
    String strSiteMapFilePath = AppPathService.getWebAppPath() + FILE_SITEMAP;
    File fileSiteMap = new File(strSiteMapFilePath);

    String strResult = "OK";

    try {
        FileUtils.writeStringToFile(fileSiteMap, strXmlSitemap);
    } catch (IOException e) {
        AppLogService.error("Error writing Sitemap file : " + e.getMessage(), e.getCause());
        strResult = "Error : " + e.getMessage();
    }

    String strDate = DateFormat.getDateTimeInstance().format(new Date());
    Object[] args = { strDate, list.size(), strResult };
    String strLogFormat = I18nService.getLocalizedString(PROPERTY_SITEMAP_LOG, Locale.getDefault());
    String strLog = MessageFormat.format(strLogFormat, args);
    DatastoreService.setDataValue(SEODataKeys.KEY_SITEMAP_UPDATE_LOG, strLog);

    return strLog;
}

From source file:org.springframework.data.hadoop.pig.PigUtils.java

static DataAccessException convert(IOException ex) {
    Throwable cause = ex.getCause();
    if (cause instanceof PigException) {
        return convert((PigException) ex);
    }//from  w ww. ja v  a2  s  .  c o m

    return new NonTransientDataAccessResourceException("Unknown Pig error", ex);
}

From source file:org.mariotaku.twidere.util.SaveFileTask.java

public static File saveFile(final Context context, final File source, final String mimeType,
        final File destination) {
    if (context == null && source == null)
        return null;
    Source ioSrc = null;/*from  w  w  w .j av  a  2s  .  c o m*/
    BufferedSink sink = null;
    try {
        final String name = source.getName();
        if (isEmpty(name))
            return null;
        final MimeTypeMap map = MimeTypeMap.getSingleton();
        final String extension = map.getExtensionFromMimeType(mimeType);
        if (extension == null)
            return null;
        final String nameToSave = getFileNameWithExtension(name, extension);
        if (!destination.isDirectory() && !destination.mkdirs())
            return null;
        final File saveFile = new File(destination, nameToSave);
        ioSrc = Okio.source(source);
        sink = Okio.buffer(Okio.sink(saveFile));
        sink.writeAll(ioSrc);
        sink.flush();
        if (mimeType != null) {
            MediaScannerConnection.scanFile(context, new String[] { saveFile.getPath() },
                    new String[] { mimeType }, null);
        }
        return saveFile;
    } catch (final IOException e) {
        final int errno = Utils.getErrorNo(e.getCause());
        Log.w(LOGTAG, "Failed to save file", e);
        return null;
    } finally {
        Utils.closeSilently(sink);
        Utils.closeSilently(ioSrc);
    }
}

From source file:org.apache.hadoop.fs.DeleteUtils.java

static public void delete(Configuration conf, Path src, FileSystem srcFs, boolean recursive, boolean skipTrash,
        boolean ignoreNonEmpty, boolean onlyDeleteFile) throws IOException {
    FileStatus fs = null;/*from  w  w w. j  a v a 2s . com*/
    try {
        fs = srcFs.getFileStatus(src);
    } catch (FileNotFoundException fnfe) {
        // Have to re-throw so that console output is as expected
        throw new FileNotFoundException("cannot remove " + src + ": No such file or directory.");
    }

    if (fs.isDir() && !recursive) {
        // We may safely delete empty directories if
        // the recursive option is not specified
        FileStatus children[] = srcFs.listStatus(src);
        if (onlyDeleteFile || (children != null && children.length != 0)) {
            if (ignoreNonEmpty) {
                return;
            } else {
                throw new IOException("Cannot remove directory \"" + src + "\"," + " use -rmr instead");
            }
        } else if (children == null) {
            throw new IOException(src + " no longer exists");
        }
    }

    if (!skipTrash) {
        try {
            Trash trashTmp = new Trash(srcFs, conf);
            if (trashTmp.moveToTrash(src)) {
                System.err.println("Moved to trash: " + src);
                return;
            }
        } catch (IOException e) {
            Exception cause = (Exception) e.getCause();
            String msg = "";
            if (cause != null) {
                msg = cause.getLocalizedMessage();
            }
            System.err.println("Problem with Trash." + msg + ". Consider using -skipTrash option");
            throw e;
        }
    }

    if (srcFs.delete(src, recursive, true)) {
        System.err.println("Deleted " + src);
    } else {
        throw new IOException("Delete failed " + src);
    }
}