Package com.btaz.util

Examples of com.btaz.util.DataUtilException


            }
            writer.flush();
            writer.close();
            writer = null;
        } catch (UnsupportedEncodingException e) {
            throw new DataUtilException(e);
        } catch (FileNotFoundException e) {
            throw new DataUtilException(e);
        } catch (IOException e) {
            throw new DataUtilException(e);
        } finally {
            if(writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
View Full Code Here


     */
    public static List<File> map(File workDir, List<File> inputFiles, Mapper mapper, String prefix)
            throws DataUtilException {
        // validations
        if(workDir == null) {
            throw new DataUtilException("The workDir parameter can not be a null value");
        }
        if(inputFiles == null) {
            throw new DataUtilException("The inputFiles parameter can not be a null value");
        }
        if(mapper == null) {
            throw new DataUtilException("The mappable parameter can not be a null value");
        }
        if(prefix == null) {
            prefix = "map";
        }

        // setup output collector
        FileOutputCollector collector = new FileOutputCollector(workDir, prefix);

        // map all data
        try {
            for(File file : inputFiles) {
                FileInputStream inputStream;

                try {
                    inputStream = new FileInputStream(file);
                    BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,
                            DataUtilDefaults.charSet));

                    // map data
                    String row;
                    while((row = br.readLine()) != null) {
                        mapper.map(row, collector);
                    }

                    inputStream.close();
                } catch (IOException e) {
                    throw new DataUtilException(e);
                } catch (MapReduceException e) {
                    throw new DataUtilException("Irrecoverable map operation", e);
                }
            }
        } finally {
            collector.close();
        }
View Full Code Here

        this.tableColumns = tableColumns;
        encoding = "UTF8";

        // validations
        if(outputFile == null) {
            throw new DataUtilException("The outputFile field can not be a null value");
        }
        if(pageTitle == null) {
            pageTitle = "";
        }
        if(tableColumns < 1) {
            throw new DataUtilException("You must have at least one column. Invalid column value: " + tableColumns);
        }

        try {
            // our output HTML file
            writer = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile.getAbsoluteFile(), false), Charset.forName(encoding)));

            // setup freemarker
            cfg = new Configuration();
            cfg.setClassForTemplateLoading(this.getClass(), "/templates");
            cfg.setObjectWrapper(new DefaultObjectWrapper());
            cfg.setDefaultEncoding(encoding);
            cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
            cfg.setIncompatibleImprovements(new Version(2, 3, 20))// FreeMarker 2.3.20

            // render header
            Map<String,Object> root = new HashMap<String,Object>();
            root.put("pageTitle", pageTitle);
            Template template = cfg.getTemplate("html-table-header.ftl");
            template.process(root, writer);
        } catch (FileNotFoundException e) {
            throw new DataUtilException("Failed to open an HTML table file", e);
        } catch (IOException e) {
            throw new DataUtilException("Failed to open an HTML table file", e);
        } catch (TemplateException e) {
            throw new DataUtilException("Failed to write the HTML table file header", e);
        }
    }
View Full Code Here

     * @param columns columns
     * @throws DataUtilException exception
     */
    public void write(String... columns) throws DataUtilException {
        if(columns.length != tableColumns) {
            throw new DataUtilException("Invalid column count. Expected " + tableColumns + " but found: "
                    + columns.length);
        }
        StringBuilder html = new StringBuilder();
        html.append("<tr>");
        for(String data : columns) {
            html.append("<td>").append(HtmlEscape.escape(data)).append("</td>");
        }
        html.append("</tr>\n");
        try {
            writer.write(html.toString());
        } catch (IOException e) {
            throw new DataUtilException("Failed to write the HTML table file", e);
        }
    }
View Full Code Here

                template.process(null, writer);
                writer.close();
                writer = null;
            }
        } catch (IOException e) {
            throw new DataUtilException("Failed to close the HTML table file", e);
        } catch (TemplateException e) {
            throw new DataUtilException("Failed to close the HTML table file", e);
        }
    }
View Full Code Here

TOP

Related Classes of com.btaz.util.DataUtilException

Copyright © 2018 www.massapicom. 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.