use of java.io.FileWriter in project flink by apache.
the class MassiveStringSorting method generateFileWithStringTuples.
private File generateFileWithStringTuples(int numStrings, String prefix) throws IOException {
final Random rnd = new Random(SEED);
final StringBuilder bld = new StringBuilder();
File f = File.createTempFile("strings", "txt");
BufferedWriter wrt = null;
try {
wrt = new BufferedWriter(new FileWriter(f));
for (int i = 0; i < numStrings; i++) {
bld.setLength(0);
int numComps = rnd.nextInt(5) + 1;
for (int z = 0; z < numComps; z++) {
if (z > 0) {
bld.append(' ');
}
bld.append(prefix);
int len = rnd.nextInt(20) + 10;
for (int k = 0; k < len; k++) {
char c = (char) (rnd.nextInt(80) + 40);
bld.append(c);
}
}
String str = bld.toString();
wrt.write(str);
wrt.newLine();
}
} finally {
wrt.close();
}
return f;
}
use of java.io.FileWriter in project flink by apache.
the class MassiveStringValueSorting method generateFileWithStringTuples.
private File generateFileWithStringTuples(int numStrings, String prefix) throws IOException {
final Random rnd = new Random(SEED);
final StringBuilder bld = new StringBuilder();
File f = File.createTempFile("strings", "txt");
BufferedWriter wrt = null;
try {
wrt = new BufferedWriter(new FileWriter(f));
for (int i = 0; i < numStrings; i++) {
bld.setLength(0);
int numComps = rnd.nextInt(5) + 1;
for (int z = 0; z < numComps; z++) {
if (z > 0) {
bld.append(' ');
}
bld.append(prefix);
int len = rnd.nextInt(20) + 10;
for (int k = 0; k < len; k++) {
char c = (char) (rnd.nextInt(80) + 40);
bld.append(c);
}
}
String str = bld.toString();
wrt.write(str);
wrt.newLine();
}
} finally {
if (wrt != null) {
wrt.close();
}
}
return f;
}
use of java.io.FileWriter in project hadoop by apache.
the class TestFileSignerSecretProvider method testGetSecrets.
@Test
public void testGetSecrets() throws Exception {
File testDir = new File(System.getProperty("test.build.data", "target/test-dir"));
testDir.mkdirs();
String secretValue = "hadoop";
File secretFile = new File(testDir, "http-secret.txt");
Writer writer = new FileWriter(secretFile);
writer.write(secretValue);
writer.close();
FileSignerSecretProvider secretProvider = new FileSignerSecretProvider();
Properties secretProviderProps = new Properties();
secretProviderProps.setProperty(AuthenticationFilter.SIGNATURE_SECRET_FILE, secretFile.getAbsolutePath());
secretProvider.init(secretProviderProps, null, -1);
Assert.assertArrayEquals(secretValue.getBytes(), secretProvider.getCurrentSecret());
byte[][] allSecrets = secretProvider.getAllSecrets();
Assert.assertEquals(1, allSecrets.length);
Assert.assertArrayEquals(secretValue.getBytes(), allSecrets[0]);
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testReload.
public void testReload() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("test.key1", "final-value1", true);
appendProperty("test.key2", "value2");
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
out = new BufferedWriter(new FileWriter(CONFIG2));
startConfig();
appendProperty("test.key1", "value1");
appendProperty("test.key3", "value3");
endConfig();
Path fileResource1 = new Path(CONFIG2);
conf.addResource(fileResource1);
// add a few values via set.
conf.set("test.key3", "value4");
conf.set("test.key4", "value5");
assertEquals("final-value1", conf.get("test.key1"));
assertEquals("value2", conf.get("test.key2"));
assertEquals("value4", conf.get("test.key3"));
assertEquals("value5", conf.get("test.key4"));
// change values in the test file...
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("test.key1", "final-value1");
appendProperty("test.key3", "final-value3", true);
endConfig();
conf.reloadConfiguration();
assertEquals("value1", conf.get("test.key1"));
// overlayed property overrides.
assertEquals("value4", conf.get("test.key3"));
assertEquals(null, conf.get("test.key2"));
assertEquals("value5", conf.get("test.key4"));
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testEnumFromXml.
public void testEnumFromXml() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG_FOR_ENUM));
startConfig();
appendProperty("test.enum", " \t \n FOO \t \n");
appendProperty("test.enum2", " \t \n Yak.FOO \t \n");
endConfig();
Configuration conf = new Configuration();
Path fileResource = new Path(CONFIG_FOR_ENUM);
conf.addResource(fileResource);
assertSame(Yak.FOO, conf.getEnum("test.enum", Yak.FOO));
boolean fail = false;
try {
conf.getEnum("test.enum2", Yak.FOO);
} catch (IllegalArgumentException e) {
fail = true;
}
assertTrue(fail);
}
Aggregations