Example #1
0
  @Test
  public void canFollowLogfile() throws IOException {
    File tempFile =
        File.createTempFile("commons-io", "", new File(System.getProperty("java.io.tmpdir")));
    tempFile.deleteOnExit();
    System.out.println("Temp file = " + tempFile.getAbsolutePath());
    PrintStream log = new PrintStream(tempFile);
    LogfileFollower follower = new LogfileFollower(tempFile);
    List<String> lines;

    // Empty file:
    lines = follower.newLines();
    assertEquals(0, lines.size());

    // Write two lines:
    log.println("Line 1");
    log.println("Line 2");
    lines = follower.newLines();
    assertEquals(2, lines.size());
    assertEquals("Line 2", lines.get(1));

    // Write one more line:
    log.println("Line 3");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 3", lines.get(0));

    // Write one and a half line and finish later:
    log.println("Line 4");
    log.print("Line 5 begin");
    lines = follower.newLines();
    assertEquals(1, lines.size());

    // End last line and start a new one:
    log.println(" end");
    log.print("Line 6 begin");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 5 begin end", lines.get(0));

    // End last line:
    log.println(" end");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 6 begin end", lines.get(0));

    // A line only missing a newline:
    log.print("Line 7");
    lines = follower.newLines();
    assertEquals(0, lines.size());
    log.println();
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 7", lines.get(0));

    // Delete:
    log.close();
    lines = follower.newLines();
    assertEquals(0, lines.size());
  }
  @Test
  public void testJson() throws Exception {
    MultiLayerConfiguration conf =
        new NeuralNetConfiguration.Builder()
            .list()
            .layer(0, new RBM.Builder().dist(new NormalDistribution(1, 1e-1)).build())
            .inputPreProcessor(0, new ReshapePreProcessor())
            .build();

    String json = conf.toJson();
    MultiLayerConfiguration from = MultiLayerConfiguration.fromJson(json);
    assertEquals(conf.getConf(0), from.getConf(0));

    Properties props = new Properties();
    props.put("json", json);
    String key = props.getProperty("json");
    assertEquals(json, key);
    File f = new File("props");
    f.deleteOnExit();
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
    props.store(bos, "");
    bos.flush();
    bos.close();
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
    Properties props2 = new Properties();
    props2.load(bis);
    bis.close();
    assertEquals(props2.getProperty("json"), props.getProperty("json"));
    String json2 = props2.getProperty("json");
    MultiLayerConfiguration conf3 = MultiLayerConfiguration.fromJson(json2);
    assertEquals(conf.getConf(0), conf3.getConf(0));
  }
 public static void writePackage(KnowledgePackage pkg, File dest) {
   dest.deleteOnExit();
   OutputStream out = null;
   try {
     out = new BufferedOutputStream(new FileOutputStream(dest));
     DroolsStreamUtils.streamOut(out, pkg);
   } catch (Exception e) {
     throw new RuntimeException(e);
   } finally {
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
       }
     }
   }
 }
Example #4
0
  @Test
  public void testUncompress_withSymbolicLinks() throws IOException, ArchiveException {
    final File inputFile = new File(inputUrl.getPath(), "tarLink.tar.gz");
    final File temporaryDirectory = Files.createTempDir();

    temporaryDirectory.deleteOnExit();

    final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory);

    final File file1 = new File(temporaryDirectory, "file1.txt");
    final File file2 = new File(temporaryDirectory, "file1_link.txt");

    assertTrue(file1.exists());
    assertTrue(file2.exists());

    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1)));
    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file2)));

    assertTrue(java.nio.file.Files.isSymbolicLink(Paths.get(file2.getPath())));
  }
Example #5
0
  private void testUncompress(String fileName) throws IOException, ArchiveException {
    final File inputFile = new File(inputUrl.getPath(), fileName);
    final File temporaryDirectory = Files.createTempDir();

    temporaryDirectory.deleteOnExit();

    final List<File> extractedFiles = new Extractor().uncompress(inputFile, temporaryDirectory);

    assertTrue(new File(temporaryDirectory, "directory1").isDirectory());
    final File file1 = new File(temporaryDirectory, "file1.txt");
    final File file2 = new File(temporaryDirectory, "file2.txt");
    final File file0 = new File(new File(temporaryDirectory, "directory1"), "file0.txt");

    assertTrue(file1.exists());
    assertTrue(file2.exists());
    assertTrue(file0.exists());

    assertEquals("file1content", new String(FileUtils.readFileToByteArray(file1)));
    assertEquals("file2content", new String(FileUtils.readFileToByteArray(file2)));
    assertEquals("file0content", new String(FileUtils.readFileToByteArray(file0)));

    assertEquals(5, extractedFiles.size());
  }