Example usage for org.apache.commons.io IOUtils closeQuietly

List of usage examples for org.apache.commons.io IOUtils closeQuietly

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils closeQuietly.

Prototype

public static void closeQuietly(OutputStream output) 

Source Link

Document

Unconditionally close an OutputStream.

Usage

From source file:com.enitalk.controllers.youtube.CalendarTest.java

public static void main(String[] args) throws IOException {

    InputStream is = new ClassPathResource("events.json").getInputStream();
    ObjectMapper jackson = new ObjectMapper();
    JsonNode tree = jackson.readTree(is);
    IOUtils.closeQuietly(is);

    DateTimeFormatter fmtDateTime = ISODateTimeFormat.dateTimeNoMillis();
    DateTimeFormatter fmt = ISODateTimeFormat.date();

    TreeMultimap<DateTime, DateTime> set = CalendarTest.getPeriodSet(10, 18);

    Iterator<JsonNode> nodes = tree.elements();
    while (nodes.hasNext()) {
        JsonNode ev = nodes.next();/*from w  w w. j a va2  s .c  o  m*/
        boolean isFullDay = ev.path("start").has("date");

        DateTime stDate = isFullDay ? fmt.parseDateTime(ev.path("start").path("date").asText())
                : fmtDateTime.parseDateTime(ev.path("start").path("dateTime").asText());

        DateTime enDate = isFullDay ? fmt.parseDateTime(ev.path("end").path("date").asText())
                : fmtDateTime.parseDateTime(ev.path("end").path("dateTime").asText());

        System.out.println("St " + stDate + " en " + enDate);

        int days = Days.daysBetween(stDate, enDate).getDays();
        System.out.println("Days between " + days);
        if (isFullDay) {
            switch (days) {
            case 1:
                set.removeAll(stDate);
                break;
            default:
                while (days-- > 0) {
                    set.removeAll(stDate.plusDays(days));
                }
            }
        } else {
            DateTime copySt = stDate.minuteOfHour().setCopy(0).secondOfMinute().setCopy(0);
            DateTime copyEn = enDate.plusHours(1).minuteOfHour().setCopy(0).secondOfMinute().setCopy(0);

            //                System.out.println("Dates truncated " + copySt + " " + copyEn);
            //                System.out.println("Ll set " + set);

            //                System.out.println("Getting set for key " + stDate.millisOfDay().setCopy(0));
            SortedSet<DateTime> ss = set.get(stDate.millisOfDay().setCopy(0));
            SortedSet<DateTime> subset = ss.subSet(copySt, copyEn);
            subset.clear();
            set.remove(enDate.millisOfDay().setCopy(0), copyEn);
        }

    }

}

From source file:com.idega.util.Stripper.java

public static void main(String[] args) {
    // Stripper stripper1 = new Stripper();

    if (args.length != 2) {
        System.err.println("Auli.  tt a hafa tvo parametra me essu, innskr og tskr");

        return;/*from ww w  .j a  v  a 2  s .  com*/
    }

    BufferedReader in = null;
    BufferedWriter out = null;

    try {
        in = new BufferedReader(new FileReader(args[0]));
    } catch (java.io.FileNotFoundException e) {
        System.err.println("Auli. Error : " + e.toString());

        return;
    }

    try {
        out = new BufferedWriter(new FileWriter(args[1]));
    } catch (java.io.IOException e) {
        System.err.println("Auli. Error : " + e.toString());
        IOUtils.closeQuietly(in);
        return;
    }

    try {
        String input = in.readLine();
        int count = 0;
        while (input != null) {
            int index = input.indexOf("\\CVS\\");
            if (index > -1) {
                System.out.println("Skipping : " + input);
                count++;
            } else {
                out.write(input);
                out.newLine();
            }

            input = in.readLine();
        }
        System.out.println("Skipped : " + count);
    } catch (java.io.IOException e) {
        System.err.println("Error reading or writing file : " + e.toString());
    }

    try {
        in.close();
        out.close();
    } catch (java.io.IOException e) {
        System.err.println("Error closing files : " + e.toString());
    }
}

From source file:com.textocat.textokit.segmentation.GenerateOSPLSplitterDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/" + OneSentencePerLineSplitter.class.getName().replace('.', '/')
            + ".xml";
    AnalysisEngineDescription desc = OneSentencePerLineSplitter.createDescription();
    FileOutputStream out = FileUtils.openOutputStream(new File(outputPath));
    try {/*from   www . jav  a2 s  .  c o  m*/
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:net.awl.edoc.pdfa.compression.FlateDecode.java

public static void main(String[] args) throws Exception {
    Inflater inf = new Inflater(false);

    File f = new File("resources/content_2_0.ufd");
    FileInputStream fis = new FileInputStream(f);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOUtils.copy(fis, baos);//from  ww  w.j ava 2s.c  o m
    IOUtils.closeQuietly(fis);
    IOUtils.closeQuietly(baos);
    byte[] buf = baos.toByteArray();
    inf.setInput(buf);
    byte[] res = new byte[buf.length];
    int size = inf.inflate(res);
    String s = new String(res, 0, size, "utf8");
    System.err.println(s);

}

From source file:net.socket.bio.TimeServer.java

/**
 * @param args//from   ww  w.  j a v  a  2s  . c  o m
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    int port = 8089;
    if (args != null && args.length > 0) {

        try {
            port = Integer.valueOf(args[0]);
        } catch (NumberFormatException e) {
            // 
        }

    }
    ServerSocket server = null;
    try {
        server = new ServerSocket(port);
        System.out.println("The time server is start in port : " + port);
        Socket socket = null;
        while (true) {
            socket = server.accept();
            System.out.println("socket name" + socket);
            new Thread(new TimeServerHandler(socket)).start();
        }
    } finally {
        IOUtils.closeQuietly(server);
    }
}

From source file:com.textocat.textokit.tokenizer.simple.GeneratePostTokenizerDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/com/textocat/textokit/tokenizer/simple/PostTokenizer.xml";
    TypeSystemDescription tsDesc = TokenizerAPI.getTypeSystemDescription();
    AnalysisEngineDescription desc = createEngineDescription(PostTokenizer.class, tsDesc);
    FileOutputStream out = new FileOutputStream(outputPath);
    try {//w  w  w .  j a v a2  s.  c o  m
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.tokenizer.simple.GenerateInitialTokenizerDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/com/textocat/textokit/tokenizer/simple/InitialTokenizer.xml";
    TypeSystemDescription tsDesc = TokenizerAPI.getTypeSystemDescription();
    AnalysisEngineDescription desc = createEngineDescription(InitialTokenizer.class, tsDesc);
    FileOutputStream out = new FileOutputStream(outputPath);
    try {//ww  w. j  a  va2  s  . com
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.segmentation.GenerateParagraphSplitterDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/" + ParagraphSplitter.class.getName().replace('.', '/') + ".xml";
    TypeSystemDescription tsDesc = SentenceSplitterAPI.getTypeSystemDescription();
    AnalysisEngineDescription desc = createEngineDescription(ParagraphSplitter.class, tsDesc);
    FileOutputStream out = FileUtils.openOutputStream(new File(outputPath));
    try {/*ww  w. jav  a2 s  . c  om*/
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.segmentation.GenerateSentenceSplitterDescriptor.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    String outputPath = "src/main/resources/" + SentenceSplitterAPI.AE_SENTENCE_SPLITTER.replace('.', '/')
            + ".xml";
    TypeSystemDescription tsDesc = SentenceSplitterAPI.getTypeSystemDescription();
    AnalysisEngineDescription desc = createEngineDescription(SentenceSplitter.class, tsDesc);
    FileOutputStream out = FileUtils.openOutputStream(new File(outputPath));
    try {// w  w w.j a  v  a 2  s  . c  o  m
        desc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.textocat.textokit.postagger.opennlp.GeneratePipelineDescriptorForOpenNLPPosTagger.java

public static void main(String[] args) throws UIMAException, IOException, SAXException {
    if (args.length != 1) {
        System.err.println("Provide output path!");
        System.exit(1);//  w  ww  .ja va2s . c  o  m
    }
    File outFile = new File(args[0]);
    //
    AnalysisEngineDescription outDesc = getDescription();
    OutputStream out = FileUtils.openOutputStream(outFile);
    try {
        outDesc.toXML(out);
    } finally {
        IOUtils.closeQuietly(out);
    }
}