use of java.io.BufferedWriter in project jna by java-native-access.
the class Kernel32Test method testGetPrivateProfileSection.
public final void testGetPrivateProfileSection() throws IOException {
final File tmp = File.createTempFile("testGetPrivateProfileSection", ".ini");
tmp.deleteOnExit();
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
try {
writer.println("[X]");
writer.println("A=1");
writer.println("B=X");
} finally {
writer.close();
}
final char[] buffer = new char[9];
final DWORD len = Kernel32.INSTANCE.GetPrivateProfileSection("X", buffer, new DWORD(buffer.length), tmp.getCanonicalPath());
assertEquals(len.intValue(), 7);
assertEquals(new String(buffer), "A=1\0B=X\0\0");
}
use of java.io.BufferedWriter in project jna by java-native-access.
the class Kernel32UtilTest method testWritePrivateProfileSection.
public final void testWritePrivateProfileSection() throws IOException {
final File tmp = File.createTempFile("testWritePrivateProfileSecion", "ini");
tmp.deleteOnExit();
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
try {
writer.println("[S1]");
writer.println("A=1");
writer.println("B=X");
writer.println("[S2]");
writer.println("C=2");
writer.println("foo=bar");
} finally {
writer.close();
}
Kernel32Util.writePrivateProfileSection("S1", new String[] { "A=3", "E=Z" }, tmp.getCanonicalPath());
final BufferedReader reader = new BufferedReader(new FileReader(tmp));
try {
assertEquals(reader.readLine(), "[S1]");
assertEquals(reader.readLine(), "A=3");
assertEquals(reader.readLine(), "E=Z");
assertEquals(reader.readLine(), "[S2]");
assertEquals(reader.readLine(), "C=2");
assertEquals(reader.readLine(), "foo=bar");
} finally {
reader.close();
}
}
use of java.io.BufferedWriter in project jna by java-native-access.
the class Kernel32Test method testWritePrivateProfileSection.
public final void testWritePrivateProfileSection() throws IOException {
final File tmp = File.createTempFile("testWritePrivateProfileSection", ".ini");
tmp.deleteOnExit();
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
try {
writer.println("[S1]");
writer.println("A=1");
writer.println("B=X");
} finally {
writer.close();
}
final boolean result = Kernel32.INSTANCE.WritePrivateProfileSection("S1", "A=3\0E=Z\0\0", tmp.getCanonicalPath());
assertTrue(result);
final BufferedReader reader = new BufferedReader(new FileReader(tmp));
assertEquals(reader.readLine(), "[S1]");
assertTrue(reader.readLine().matches("A\\s*=\\s*3"));
assertTrue(reader.readLine().matches("E\\s*=\\s*Z"));
reader.close();
}
use of java.io.BufferedWriter in project jna by java-native-access.
the class Kernel32Test method testWritePrivateProfileString.
public final void testWritePrivateProfileString() throws IOException {
final File tmp = File.createTempFile("testWritePrivateProfileString", ".ini");
tmp.deleteOnExit();
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
writer.println("[Section]");
writer.println("existingKey = ABC");
writer.println("removedKey = JKL");
writer.close();
assertTrue(Kernel32.INSTANCE.WritePrivateProfileString("Section", "existingKey", "DEF", tmp.getCanonicalPath()));
assertTrue(Kernel32.INSTANCE.WritePrivateProfileString("Section", "addedKey", "GHI", tmp.getCanonicalPath()));
assertTrue(Kernel32.INSTANCE.WritePrivateProfileString("Section", "removedKey", null, tmp.getCanonicalPath()));
final BufferedReader reader = new BufferedReader(new FileReader(tmp));
assertEquals(reader.readLine(), "[Section]");
assertTrue(reader.readLine().matches("existingKey\\s*=\\s*DEF"));
assertTrue(reader.readLine().matches("addedKey\\s*=\\s*GHI"));
assertEquals(reader.readLine(), null);
reader.close();
}
use of java.io.BufferedWriter in project jna by java-native-access.
the class Kernel32Test method testGetPrivateProfileSectionNames.
public final void testGetPrivateProfileSectionNames() throws IOException {
final File tmp = File.createTempFile("testGetPrivateProfileSectionNames", ".ini");
tmp.deleteOnExit();
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
try {
writer.println("[S1]");
writer.println("[S2]");
} finally {
writer.close();
}
final char[] buffer = new char[7];
final DWORD len = Kernel32.INSTANCE.GetPrivateProfileSectionNames(buffer, new DWORD(buffer.length), tmp.getCanonicalPath());
assertEquals(len.intValue(), 5);
assertEquals(new String(buffer), "S1\0S2\0\0");
}
Aggregations