Code example for Closer

Methods: register

0
 
		// Populate the file with data. 
		PrintWriter w = 
		    new PrintWriter(
		        new OutputStreamWriter(
		            closer.register(new FileOutputStream(input)), "UTF-8"));
		w.println("passagère\tpassager\ttag");
		w.println("nieduży\tduży\ttest");
		w.print("abcd\tabc\txyz");
		w.close();
 
		// suffix 
		MorphEncodingTool.main(new String[] { 
				"--input", input.getAbsolutePath(), 
				"--output", output.getAbsolutePath(), 
				"--encoder", "suffix" }); 
 
		BufferedReader testOutput = 
		    new BufferedReader(
		        new InputStreamReader(
		            closer.register(new FileInputStream(output.getAbsolutePath())), "UTF-8"));
		Assert.assertEquals("passagère+Eer+tag", testOutput.readLine());
		Assert.assertEquals("nieduży+Iduży+test", testOutput.readLine());
		Assert.assertEquals("abcd+B+xyz", testOutput.readLine());
 
		// prefix 
		MorphEncodingTool.main(new String[] { 
				"--input", input.getAbsolutePath(), 
				"--output", output.getAbsolutePath(), 
				"--encoder", "prefix" }); 
 
		testOutput = 
		    new BufferedReader(
		        new InputStreamReader(
		            closer.register(new FileInputStream(output.getAbsolutePath())), "UTF-8"));
		Assert.assertEquals("passagère+AEer+tag", testOutput.readLine());
		Assert.assertEquals("nieduży+DA+test", testOutput.readLine());
		Assert.assertEquals("abcd+AB+xyz", testOutput.readLine());
 
		// infix 
		MorphEncodingTool.main(new String[] { 
				"--input", input.getAbsolutePath(), 
				"--output", output.getAbsolutePath(), 
				"--encoder", "infix" }); 
 
		testOutput = 
		    new BufferedReader(
		        new InputStreamReader(
		            closer.register(new FileInputStream(output.getAbsolutePath())), "UTF-8"));
		Assert.assertEquals("passagère+GDAr+tag", testOutput.readLine());
		Assert.assertEquals("nieduży+ADA+test", testOutput.readLine());
		Assert.assertEquals("abcd+AAB+xyz", testOutput.readLine());
 
		// custom annotation - test tabs 
        MorphEncodingTool.main(new String[] {
                "--annotation", "\t", 
                "--input", input.getAbsolutePath(), 
                "--output", output.getAbsolutePath(), 
                "--encoder", "infix" }); 
 
        testOutput = 
            new BufferedReader(
                new InputStreamReader(
                    closer.register(new FileInputStream(output.getAbsolutePath())), "UTF-8"));
        Assert.assertEquals("passagère\tGDAr\ttag", testOutput.readLine());
        Assert.assertEquals("nieduży\tADA\ttest", testOutput.readLine());
        Assert.assertEquals("abcd\tAAB\txyz", testOutput.readLine());
	}