public static void main(String[] args) {
    if (args == null || args.length != 2) {
      System.err.println(
          "usage: java " + NumberKeywordsSample.class + "<in dir (docs)> <out file>");
      System.exit(1);
    }

    File in = new File(args[0]);
    if (!in.isDirectory()) {
      System.err.println("Given parameter " + in + " is not a directory");
      System.exit(1);
    }

    File out = new File(args[1]);
    if (out.exists()) {
      System.err.println("Given parameter " + out + " does not exist");
      System.exit(1);
    }

    FiveMostPopularPerCategoryFinder processor = new FiveMostPopularPerCategoryFinder(out);
    for (File inf : in.listFiles()) {
      try {
        YoutubeVideo video = XStreamer.loadObjectFromFile(inf, YoutubeVideo.class);
        processor.addRawXml(video);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    processor.terminate();
  }
Exemplo n.º 2
0
 public static void saveObjectToFile(File file, Object o) throws IOException {
   BufferedOutputStream out = null;
   try {
     out = new BufferedOutputStream(new FileOutputStream(file));
     XStreamer.stream(o, out);
     out.flush();
   } finally {
     if (out != null) out.close();
   }
 }
Exemplo n.º 3
0
 public static <T> T loadObjectFromFile(File file, Class<T> clazz) throws IOException {
   BufferedInputStream in = null;
   try {
     in = new BufferedInputStream(new FileInputStream(file));
     T video = clazz.cast(XStreamer.destream(in));
     return video;
   } finally {
     if (in != null) in.close();
   }
 }
 private static void processFile(File f, DocumentProcessor<Object> processor) throws IOException {
   Document document = XStreamer.loadObjectFromFile(f, Document.class);
   /* Since we're trying to match tag-combinations to categories, we'll skip
    * any documents which don't have any category information
    */
   if (document.getSpace(SpaceType.CATEGORY) != null) {
     Space tagSpace = document.getSpace(SpaceType.TAG);
     processor.addTextInfo(document, tagSpace);
   }
 }