Java 类com.google.common.io.Flushables 实例源码

项目:checkstyle-backport-jre6    文件:PropertyCacheFileTest.java   
@Test
public void testCloseAndFlushOutputStreamAfterCreatingHashCode() throws IOException {
    mockStatic(Closeables.class);
    doNothing().when(Closeables.class);
    Closeables.close(any(ObjectOutputStream.class), Matchers.eq(false));
    mockStatic(Flushables.class);
    doNothing().when(Flushables.class);
    Flushables.flush(any(ObjectOutputStream.class), Matchers.eq(false));

    final Configuration config = new DefaultConfiguration("myName");
    final PropertyCacheFile cache = new PropertyCacheFile(config, "fileDoesNotExist.txt");
    cache.load();

    verifyStatic(times(1));

    Closeables.close(any(ObjectOutputStream.class), Matchers.eq(false));
    verifyStatic(times(1));
    Flushables.flush(any(ObjectOutputStream.class), Matchers.eq(false));
}
项目:checkstyle-backport-jre6    文件:PropertyCacheFileTest.java   
@Test
public void testFlushAndCloseCacheFileOutputStream() throws IOException {
    mockStatic(Closeables.class);
    doNothing().when(Closeables.class);
    Closeables.close(any(FileOutputStream.class), Matchers.eq(false));
    mockStatic(Flushables.class);
    doNothing().when(Flushables.class);
    Flushables.flush(any(FileOutputStream.class), Matchers.eq(false));

    final Configuration config = new DefaultConfiguration("myName");
    final PropertyCacheFile cache = new PropertyCacheFile(config,
        temporaryFolder.newFile().getPath());

    cache.put("CheckedFileName.java", System.currentTimeMillis());
    cache.persist();

    verifyStatic(times(1));
    Closeables.close(any(FileOutputStream.class), Matchers.eq(false));
    verifyStatic(times(1));
    Flushables.flush(any(FileOutputStream.class), Matchers.eq(false));
}
项目:checkstyle    文件:PropertyCacheFileTest.java   
@Test
public void testCloseAndFlushOutputStreamAfterCreatingHashCode() throws IOException {
    mockStatic(Closeables.class);
    doNothing().when(Closeables.class);
    Closeables.close(any(ObjectOutputStream.class), Matchers.eq(false));
    mockStatic(Flushables.class);
    doNothing().when(Flushables.class);
    Flushables.flush(any(ObjectOutputStream.class), Matchers.eq(false));

    final Configuration config = new DefaultConfiguration("myName");
    final PropertyCacheFile cache = new PropertyCacheFile(config, "fileDoesNotExist.txt");
    cache.load();

    verifyStatic(times(1));

    Closeables.close(any(ObjectOutputStream.class), Matchers.eq(false));
    verifyStatic(times(1));
    Flushables.flush(any(ObjectOutputStream.class), Matchers.eq(false));
}
项目:checkstyle    文件:PropertyCacheFileTest.java   
@Test
public void testFlushAndCloseCacheFileOutputStream() throws IOException {
    mockStatic(Closeables.class);
    doNothing().when(Closeables.class);
    Closeables.close(any(FileOutputStream.class), Matchers.eq(false));
    mockStatic(Flushables.class);
    doNothing().when(Flushables.class);
    Flushables.flush(any(FileOutputStream.class), Matchers.eq(false));

    final Configuration config = new DefaultConfiguration("myName");
    final PropertyCacheFile cache = new PropertyCacheFile(config,
        temporaryFolder.newFile().getPath());

    cache.put("CheckedFileName.java", System.currentTimeMillis());
    cache.persist();

    verifyStatic(times(1));
    Closeables.close(any(FileOutputStream.class), Matchers.eq(false));
    verifyStatic(times(1));
    Flushables.flush(any(FileOutputStream.class), Matchers.eq(false));
}
项目:checkstyle-backport-jre6    文件:PropertyCacheFile.java   
/**
 * Flushes and closes output stream.
 * @param stream the output stream
 * @throws IOException  when there is a problems with file flush and close
 */
private static void flushAndCloseOutStream(OutputStream stream) throws IOException {
    if (stream != null) {
        Flushables.flush(stream, false);
    }
    Closeables.close(stream, false);
}
项目:checkstyle    文件:PropertyCacheFile.java   
/**
 * Flushes and closes output stream.
 * @param stream the output stream
 * @throws IOException  when there is a problems with file flush and close
 */
private static void flushAndCloseOutStream(OutputStream stream) throws IOException {
    if (stream != null) {
        Flushables.flush(stream, false);
    }
    Closeables.close(stream, false);
}