Examples of DataUtilException


Examples of com.btaz.util.DataUtilException

                    close();
                }
                return line;
            } catch (IOException e) {
                hasMoreData = false;
                throw new DataUtilException(e);
            }
        }
View Full Code Here

Examples of com.btaz.util.DataUtilException

         */
        private void close() {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new DataUtilException(e);
            }
        }
View Full Code Here

Examples of com.btaz.util.DataUtilException

                inputStream.close();
            }
            writer.flush();
            writer.close();
        } catch (UnsupportedEncodingException e) {
            throw new DataUtilException(e);
        } catch (FileNotFoundException e) {
            throw new DataUtilException(e);
        } catch (IOException e) {
            throw new DataUtilException(e);
        }
    }
View Full Code Here

Examples of com.btaz.util.DataUtilException

            if(! ignoreSet.contains(field)) {
                headerFields.add(field);
            }
        }
        if(idCounter != 2) {
            throw new DataUtilException("Invalid header format. The \"id\" field must be present in both files");
        }
        if(headerFields.size() < h1.length || headerFields.size() < h1.length) {
            throw new DataUtilException("Invalid header format. Repeated header fields with the same name");
        }
        return headerFields;
    }
View Full Code Here

Examples of com.btaz.util.DataUtilException

    public static String readResourceAsStream(String path) {
        try {
            InputStream inputStream = ResourceUtil.getResourceAsStream(path);
            return ResourceUtil.readFromInputStreamIntoString(inputStream);
        } catch (Exception e) {
            throw new DataUtilException("Failed to load resource", e);
        }
    }
View Full Code Here

Examples of com.btaz.util.DataUtilException

    public static String readResource(String path) {
        try {
            File file = ResourceUtil.getResourceFile(path);
            return ResourceUtil.readFromFileIntoString(file);
        } catch (Exception e) {
            throw new DataUtilException("Failed to load resource", e);
        }
    }
View Full Code Here

Examples of com.btaz.util.DataUtilException

*/
public class FilePathComparator implements Comparator<File> {
    @Override
    public int compare(File o1, File o2) {
        if(o1 == null || o2 == null) {
            throw new DataUtilException("None of the file parameters can be a null value");
        }
        String [] f1 = o1.getAbsolutePath().split(File.separator);
        String [] f2 = o2.getAbsolutePath().split(File.separator);

        for(int i=0; i<Math.min(f1.length, f2.length); i++) {
View Full Code Here

Examples of com.btaz.util.DataUtilException

     */
    public static void reduce(File inputFile, File outputFile, Reducer reducer, KeyComparator comparator)
            throws DataUtilException {
        // validations
        if(inputFile == null) {
            throw new DataUtilException("The inputFile parameter can not be a null value");
        }
        if(outputFile == null) {
            throw new DataUtilException("The outputFile parameter can not be a null value");
        }
        if(reducer == null) {
            throw new DataUtilException("The reducable parameter can not be a null value");
        }
        if(comparator == null) {
            throw new DataUtilException("The comparator parameter can not be a null value");
        }

        // reduce all data
        FileInputStream inputStream;
        OutputCollector collector = new OutputCollector(outputFile);
        QueueReader queueReader;

        // Aggregate all items matching the comparator and call the Reducable callback
        try {
            inputStream = new FileInputStream(inputFile);
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,
                    DataUtilDefaults.charSet));
            queueReader = new QueueReader(br);

            // reduce data
            String prev = null;
            String curr;
            ArrayList<String> items = new ArrayList<String>();
            while(true) {
                curr = queueReader.readLine();
                if(curr == null) {
                    // no more data
                    reduceItems(collector, reducer, items);
                    break;
                } else if(prev == null) {
                    // first row in a new batch
                    items.add(curr);
                    prev = curr;
                } else if(comparator.compare(prev, curr) == 0) {
                    // same keys
                    items.add(curr);
                    prev = curr;
                } else {
                    // different keys
                    queueReader.push(curr);
                    reduceItems(collector, reducer, items);
                    items.clear();
                    prev = null;
                }
            }
            collector.close();
            inputStream.close();
        } catch (IOException e) {
            throw new DataUtilException(e);
        } catch (MapReduceException e) {
            throw new DataUtilException("Irrecoverable reduce operation", e);
        }
    }
View Full Code Here

Examples of com.btaz.util.DataUtilException

     * @param comparator comparator to use for sorting
     */
    public static List<File> sort(File sortDir, List<File> files, Comparator<String> comparator) {
        // validations
        if(sortDir == null) {
            throw new DataUtilException("The sort directory parameter can't be a null value");
        } else if(!sortDir.exists()) {
            throw new DataUtilException("The sort directory doesn't exist");
        }
        if(files == null) {
            throw new DataUtilException("The files parameter can't be a null value");
        }

        // sort files
        List<File> sortedFiles = new ArrayList<File>();
        for(File file : files) {
            FileInputStream inputStream = null;
            BufferedWriter writer = null;

            try {
                // readLine part into memory
                ArrayList<String> list = new ArrayList<String>();
                inputStream = new FileInputStream(file);
                BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, DataUtilDefaults.charSet));
                String line;
                while((line = br.readLine()) != null) {
                    list.add(line);
                }
                inputStream.close();
                inputStream = null;

                // sort
                Collections.sort(list, comparator);

                // write sorted partial
                File sortedFile = File.createTempFile("sorted-", ".part", sortDir);
                sortedFiles.add(sortedFile);

                writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
                        sortedFile.getAbsoluteFile(), false),DataUtilDefaults.charSet));

                for(String item : list) {
                    writer.write(item + DataUtilDefaults.lineTerminator);
                }
                writer.flush();
                writer.close();
                writer = null;
            } catch (FileNotFoundException e) {
                throw new DataUtilException(e);
            } catch (UnsupportedEncodingException e) {
                throw new DataUtilException(e);
            } catch (IOException e) {
                throw new DataUtilException(e);
            } finally {
                if(inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
View Full Code Here

Examples of com.btaz.util.DataUtilException

     * @param dir directory
     * @param extension filename extension
     */
    public static void deleteFilesByExtension(File dir, String extension) {
        if(extension == null) {
            throw new DataUtilException("Filename extension can not be a null value");
        }
        FilenameFilter filter = new FileExtensionFilenameFilter(extension);
        FileDeleter.deleteFiles(dir, filter);
    }
View Full Code Here
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.