Refine search
public static void deleteDir(@NotNull File dir) { try { IOTools.deleteDirWithFiles(dir, 20); } catch (Throwable e) { e.printStackTrace(); } }
@Test public void testNoHeader() throws IOException { @NotNull File dir = new File(OS.TARGET + "/deleteme-" + System.nanoTime()); dir.mkdir(); File file = new File(dir, "19700101" + SingleChronicleQueue.SUFFIX); try (FileOutputStream fos = new FileOutputStream(file)) { byte[] bytes = new byte[1024]; for (int i = 0; i < 128; i++) { fos.write(bytes); } } @NotNull ChronicleQueue queue = binary(dir) .rollCycle(RollCycles.TEST4_DAILY) .testBlockSize() .build(); testQueue(queue); queue.close(); try { IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } }
public static byte[] readFile(Class clazz, @NotNull String name) throws IOException { URL url = urlFor(clazz, name); InputStream is = open(url); return readAsBytes(is); }
@After public void after() { try { IOTools.deleteDirWithFiles(path, 2); } catch (Exception ignored) { } }
@AfterClass public static void afterClass() { for (File file : pathsToDelete) { IOTools.shallowDeleteDirWithFiles(file); } }
@Deprecated public static URL urlFor(String name) throws FileNotFoundException { // use the callers class loader not the default one if possible. return urlFor(Thread.currentThread().getContextClassLoader(), name); }
public static void createDirectories(Path dir) throws IOException { if (dir == null || dir.getNameCount() == 0 || Files.isDirectory(dir)) return; createDirectories(dir.getParent()); try { Files.createDirectory(dir); } catch (FileAlreadyExistsException e) { if (Files.isSymbolicLink(dir)) throw new IOException("Symbolic link from " + dir + " to " + Files.readSymbolicLink(dir) + " is broken", e); if (Files.isRegularFile(dir)) throw new IOException("Cannot create a directory with the same name as a file " + dir, e); } catch (AccessDeniedException e) { if (!dir.toFile().canWrite()) throw new IOException("Cannot write to " + dir, e); } }
public static byte[] readFile(Class clazz, @NotNull String name) throws IOException { URL url = urlFor(clazz, name); InputStream is = open(url); return readAsBytes(is); }
System.out.println("transport histogram: " + transportTime.toMicrosFormat()); System.out.println("read histogram: " + readTime.toMicrosFormat()); IOTools.deleteDirWithFiles(path, 2); Jvm.pause(1000);
@After public void teardown() { try { IOTools.shallowDeleteDirWithFiles(chroniclePath); } catch (Exception e) { if (e instanceof AccessDeniedException && OS.isWindows()) System.err.println(e); else throw e; } }
@Deprecated public static URL urlFor(String name) throws FileNotFoundException { // use the callers class loader not the default one if possible. return urlFor(Thread.currentThread().getContextClassLoader(), name); }
public static void createDirectories(Path dir) throws IOException { if (dir == null || dir.getNameCount() == 0 || Files.isDirectory(dir)) return; createDirectories(dir.getParent()); try { Files.createDirectory(dir); } catch (FileAlreadyExistsException e) { if (Files.isSymbolicLink(dir)) throw new IOException("Symbolic link from " + dir + " to " + Files.readSymbolicLink(dir) + " is broken", e); if (Files.isRegularFile(dir)) throw new IOException("Cannot create a directory with the same name as a file " + dir, e); } catch (AccessDeniedException e) { if (!dir.toFile().canWrite()) throw new IOException("Cannot write to " + dir, e); } }
public static boolean deleteDirWithFiles(@NotNull String... dirs) throws IORuntimeException { boolean result = false; for (String dir : dirs) { boolean r = deleteDirWithFiles(dir, 20); result |= r; } return result; }
@Test public void testEmptyDirectory() { @NotNull File dir = new File(OS.TARGET, getClass().getSimpleName() + "-" + System.nanoTime()); dir.mkdir(); @NotNull RollingChronicleQueue queue = binary(dir).testBlockSize().build(); assertEquals(Integer.MAX_VALUE, queue.firstCycle()); assertEquals(Long.MAX_VALUE, queue.firstIndex()); assertEquals(Integer.MIN_VALUE, queue.lastCycle()); queue.close(); IOTools.shallowDeleteDirWithFiles(dir.getAbsolutePath()); }
/** * This method first looks for the file in the classpath. If this is not found it * appends the suffix .gz and looks again in the classpath to see if it is present. * If it is still not found it looks for the file on the file system. If it not found * it appends the suffix .gz and looks again on the file system. * If it still not found a FileNotFoundException is thrown. * * @param name Name of the file * @return A byte[] containing the contents of the file * @throws IOException FileNotFoundException thrown if file is not found */ public static byte[] readFile(@NotNull String name) throws IOException { URL url = urlFor(name); InputStream is = open(url); return readAsBytes(is); }
@Test public void shouldDetermineQueueDirectoryFromQueueFile() { final Path path = Paths.get(OS.USER_DIR, TEST_QUEUE_FILE); try (final ChronicleQueue queue = ChronicleQueue.singleBuilder(path) .testBlockSize() .build()) { assertThat(queue.createTailer().readingDocument().isPresent(), is(false)); } finally { IOTools.deleteDirWithFiles(path.toFile(), 20); } }
@Test public void tailerToEndIncreasesRefCount() throws Exception { String path = OS.TARGET + "/toEndIncRefCount-" + System.nanoTime(); IOTools.shallowDeleteDirWithFiles(path); SetTimeProvider time = new SetTimeProvider(); long now = System.currentTimeMillis(); time.currentTimeMillis(now); ChronicleQueue queue = SingleChronicleQueueBuilder.binary(path) .testBlockSize() .rollCycle(RollCycles.TEST_SECONDLY) .timeProvider(time) .build(); final SingleChronicleQueueExcerpts.StoreAppender appender = (SingleChronicleQueueExcerpts.StoreAppender) queue.acquireAppender(); Field storeF1 = SingleChronicleQueueExcerpts.StoreAppender.class.getDeclaredField("store"); Jvm.setAccessible(storeF1); SingleChronicleQueueStore store1 = (SingleChronicleQueueStore) storeF1.get(appender); System.out.println(store1); appender.writeDocument(wire -> wire.write(() -> "msg").int32(1)); final SingleChronicleQueueExcerpts.StoreTailer tailer = (SingleChronicleQueueExcerpts.StoreTailer) queue.createTailer(); System.out.println(tailer); tailer.toEnd(); System.out.println(tailer); Field storeF2 = SingleChronicleQueueExcerpts.StoreTailer.class.getDeclaredField("store"); Jvm.setAccessible(storeF2); SingleChronicleQueueStore store2 = (SingleChronicleQueueStore) storeF2.get(tailer); // the reference count here is 1, the queue itself assertEquals(1, store2.refCount()); }
public static boolean deleteDirWithFiles(@NotNull String... dirs) throws IORuntimeException { boolean result = false; for (String dir : dirs) { boolean r = deleteDirWithFiles(dir, 20); result |= r; } return result; }