Package org.apache.zookeeper.common.AtomicFileWritingIdiom

Examples of org.apache.zookeeper.common.AtomicFileWritingIdiom.WriterStatement


            cfg.load(in);
        } finally {
            in.close();
        }

        new AtomicFileWritingIdiom(new File(configFileStr), new WriterStatement() {
            @Override
            public void write(Writer out) throws IOException {
                for (Entry<Object, Object> entry : cfg.entrySet()) {
                    String key = entry.getKey().toString().trim();
View Full Code Here


   * @param value the long value to write to the named file
   * @throws IOException if the file cannot be written atomically
   */
    private void writeLongToFile(String name, final long value) throws IOException {
        File file = new File(logFactory.getSnapDir(), name);
        new AtomicFileWritingIdiom(file, new WriterStatement() {
            @Override
            public void write(Writer bw) throws IOException {
                bw.write(Long.toString(value));
            }
        });
View Full Code Here

    public static void writeDynamicConfig(final String dynamicConfigFilename,
                                          final QuorumVerifier qv,
                                          final boolean needKeepVersion)
            throws IOException {

        new AtomicFileWritingIdiom(new File(dynamicConfigFilename), new WriterStatement() {
            @Override
            public void write(Writer out) throws IOException {
                Properties cfg = new Properties();
                cfg.load( new StringReader(
                        qv.toString()));
View Full Code Here

            cfg.load(in);
        } finally {
            in.close();
        }

        new AtomicFileWritingIdiom(new File(configFileStr), new WriterStatement() {
            @Override
            public void write(Writer out) throws IOException {
                for (Entry<Object, Object> entry : cfg.entrySet()) {
                    String key = entry.getKey().toString().trim();
View Full Code Here

   * @param value the long value to write to the named file
   * @throws IOException if the file cannot be written atomically
   */
    private void writeLongToFile(String name, final long value) throws IOException {
        File file = new File(logFactory.getSnapDir(), name);
        new AtomicFileWritingIdiom(file, new WriterStatement() {
            @Override
            public void write(Writer bw) throws IOException {
                bw.write(Long.toString(value));
            }
        });
View Full Code Here

    public void testWriterSuccess() throws IOException {
        File target = new File(tmpdir, "target.txt");
        final File tmp = new File(tmpdir, "target.txt.tmp");
        createFile(target, "before");
        assertEquals("before", getContent(target));
        new AtomicFileWritingIdiom(target, new WriterStatement() {
            @Override
            public void write(Writer os) throws IOException {
                os.write("after");
                assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists());
            }
View Full Code Here

        final File tmp = new File(tmpdir, "target.txt.tmp");
        createFile(target, "before");
        assertEquals("before", getContent(target));
        boolean exception = false;
        try {
            new AtomicFileWritingIdiom(target, new WriterStatement() {
                @Override
                public void write(Writer os) throws IOException {
                    os.write("after");
                    os.flush();
                    assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists());
View Full Code Here

        final File tmp = new File(tmpdir, "target.txt.tmp");
        createFile(target, "before");
        assertEquals("before", getContent(target));
        boolean exception = false;
        try {
            new AtomicFileWritingIdiom(target, new WriterStatement() {
                @Override
                public void write(Writer os) throws IOException {
                    os.write("after");
                    os.flush();
                    assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists());
View Full Code Here

        final File tmp = new File(tmpdir, "target.txt.tmp");
        createFile(target, "before");
        assertEquals("before", getContent(target));
        boolean exception = false;
        try {
            new AtomicFileWritingIdiom(target, new WriterStatement() {
                @Override
                public void write(Writer os) throws IOException {
                    os.write("after");
                    os.flush();
                    assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists());
View Full Code Here

    public void testWriterSuccessNE() throws IOException {
        File target = new File(tmpdir, "target.txt");
        final File tmp = new File(tmpdir, "target.txt.tmp");
        target.delete();
        assertFalse("file should not exist", target.exists());
        new AtomicFileWritingIdiom(target, new WriterStatement() {
            @Override
            public void write(Writer os) throws IOException {
                os.write("after");
                assertTrue("implementation of AtomicFileOutputStream has changed, update the test", tmp.exists());
            }
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.common.AtomicFileWritingIdiom.WriterStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.