Refine search
public File save(Reflections reflections, String filename) { try { File file = Utils.prepareFile(filename); Files.write(toString(reflections), file, Charset.defaultCharset()); return file; } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void setUp() throws IOException { rootDir = Files.createTempDir(); }
@Override public String getName() { final String ext = Files.getFileExtension(path); return Files.getNameWithoutExtension(path) + (Strings.isNullOrEmpty(ext) ? "" : ("." + ext)); }
public BenchmarkQuery(File file) throws IOException { requireNonNull(file, "file is null"); name = Files.getNameWithoutExtension(file.getName()); // file can have 2 sections separated by a line of equals signs String text = Files.toString(file, StandardCharsets.UTF_8); List<String> sections = SECTION_SPLITTER.splitToList(text); if (sections.size() == 2) { this.tags = ImmutableMap.copyOf(TAGS_SPLITTER.split(sections.get(0))); this.sql = sections.get(1); } else { // no tags this.tags = ImmutableMap.of(); this.sql = sections.get(0); } }
public void testAppendString() throws IOException { File temp = createTempFile(); Files.append(I18N, temp, Charsets.UTF_16LE); assertEquals(I18N, Files.toString(temp, Charsets.UTF_16LE)); Files.append(I18N, temp, Charsets.UTF_16LE); assertEquals(I18N + I18N, Files.toString(temp, Charsets.UTF_16LE)); Files.append(I18N, temp, Charsets.UTF_16LE); assertEquals(I18N + I18N + I18N, Files.toString(temp, Charsets.UTF_16LE)); }
@Test public void should_fire_event() throws IOException { runWithConfiguration("event.json"); File file = folder.newFile(); System.setOut(new PrintStream(new FileOutputStream(file))); assertThat(helper.get(remoteUrl("/event")), is("post_foo")); idle(IDLE, TimeUnit.MILLISECONDS); assertThat(Files.toString(file, Charset.defaultCharset()), containsString("0XCAFEBABE")); }
@Override public void run() throws IOException { assertThat(helper.postContent(remoteUrl("/proxy"), "proxy"), is("proxy")); assertThat(Files.toString(tempFile, Charset.defaultCharset()), containsString("proxy")); } });
final List<String> lines = Files.readLines(logFile, Charset.defaultCharset(), new LineProcessor<List<String>>() { private List<String> matchedLines = new LinkedList<>();
public void testNoNulCharacters(final String message, final String expected) throws IOException { @SuppressWarnings("resource") final LoggerContext loggerContext = loggerContextRule.getLoggerContext(); final Logger logger = loggerContext.getLogger("com.example"); logger.error("log:", message); loggerContext.stop(); final File file = new File(FILE_PATH); final byte[] contents = Files.toByteArray(file); int count0s = 0; final StringBuilder sb = new StringBuilder(); for (int i = 0; i < contents.length; i++) { final byte b = contents[i]; if (b == 0) { sb.append(i); sb.append(", "); count0s++; } } Assert.assertEquals("File contains " + count0s + " 0x00 byte at indices " + sb, 0, count0s); final List<String> readLines = Files.readLines(file, Charset.defaultCharset()); final String actual = readLines.get(0); // Assert.assertTrue(actual, actual.contains(message)); Assert.assertEquals(actual, expected, actual); Assert.assertEquals(1, readLines.size()); }
@Test public void testPushTaskLogDirCreationFails() throws Exception { final File tmpDir = temporaryFolder.newFolder(); final File logDir = new File(tmpDir, "druid/logs"); final File logFile = new File(tmpDir, "log"); Files.write("blah", logFile, StandardCharsets.UTF_8); if (!tmpDir.setWritable(false)) { throw new RuntimeException("failed to make tmp dir read-only"); } final TaskLogs taskLogs = new FileTaskLogs(new FileTaskLogsConfig(logDir)); expectedException.expect(IOException.class); expectedException.expectMessage("Unable to create task log dir"); taskLogs.pushTaskLog("foo", logFile); }
@Test public void testSanity() throws Exception { File baseDir = folder.newFolder("base"); try (FileSmoosher smoosher = new FileSmoosher(baseDir, 21)) { for (int i = 0; i < 20; ++i) { File tmpFile = folder.newFile(StringUtils.format("smoosh-%s.bin", i)); Files.write(Ints.toByteArray(i), tmpFile); smoosher.add(StringUtils.format("%d", i), tmpFile); } } validateOutput(baseDir); }
@Test public void testSimple() throws Exception { final File tmpDir = temporaryFolder.newFolder(); try { final File logDir = new File(tmpDir, "druid/logs"); final File logFile = new File(tmpDir, "log"); Files.write("blah", logFile, StandardCharsets.UTF_8); final TaskLogs taskLogs = new FileTaskLogs(new FileTaskLogsConfig(logDir)); taskLogs.pushTaskLog("foo", logFile); final Map<Long, String> expected = ImmutableMap.of(0L, "blah", 1L, "lah", -2L, "ah", -5L, "blah"); for (Map.Entry<Long, String> entry : expected.entrySet()) { final byte[] bytes = ByteStreams.toByteArray(taskLogs.streamTaskLog("foo", entry.getKey()).get().openStream()); final String string = StringUtils.fromUtf8(bytes); Assert.assertEquals(StringUtils.format("Read with offset %,d", entry.getKey()), string, entry.getValue()); } } finally { FileUtils.deleteDirectory(tmpDir); } }
@Test(groups = {LDAP, LDAP_CLI, PROFILE_SPECIFIC_TESTS}, timeOut = TIMEOUT) public void shouldRunQueryFromFileWithLdap() throws IOException { File temporayFile = File.createTempFile("test-sql", null); temporayFile.deleteOnExit(); Files.write("select * from hive.default.nation;\n", temporayFile, UTF_8); launchPrestoCliWithServerArgument("--file", temporayFile.getAbsolutePath()); assertThat(trimLines(presto.readRemainingOutputLines())).containsAll(nationTableBatchLines); }
private static URL makeJarUrlWithName(String name) throws IOException { File fullPath = new File(Files.createTempDir(), name); File jarFile = JarFileFinder.pickAnyJarFile(); Files.copy(jarFile, fullPath); return fullPath.toURI().toURL(); }
public static void createSourceJsonFile(File sourceJsonFile) throws IOException { Files.createParentDirs(sourceJsonFile); Files.write(SOURCE_JSON_DOCS, sourceJsonFile, ConfigurationKeys.DEFAULT_CHARSET_ENCODING); }
@Test public void canOutputSimpleRegionToFile() throws Exception { File outputFile = temporaryFolder.newFile("queryOutput.txt"); FileUtils.deleteQuietly(outputFile); CommandResult result = gfsh.executeCommand( "query --query='select * from /simpleRegion' --file=" + outputFile.getAbsolutePath()); assertThat(result.getStatus()).isEqualTo(Result.Status.OK); // .statusIsSuccess().containsOutput(outputFile.getAbsolutePath()); assertThat(outputFile).exists(); List<String> lines = Files.readLines(outputFile, StandardCharsets.UTF_8); assertThat(lines.get(7)).isEqualTo("Result"); assertThat(lines.get(8)).isEqualTo("--------"); lines.subList(9, lines.size()).forEach(line -> assertThat(line).matches("value\\d+")); }
public void testMap_readWrite() throws IOException { // Test data int size = 1024; byte[] expectedBytes = new byte[size]; byte[] bytes = newPreFilledByteArray(1024); // Setup File file = createTempFile(); Files.write(bytes, file); Random random = new Random(); random.nextBytes(expectedBytes); // Test MappedByteBuffer map = Files.map(file, MapMode.READ_WRITE); map.put(expectedBytes); // Verify byte[] actualBytes = Files.toByteArray(file); assertTrue(Arrays.equals(expectedBytes, actualBytes)); }
public void testWriteBytes() throws IOException { File temp = createTempFile(); byte[] data = newPreFilledByteArray(2000); Files.write(data, temp); assertTrue(Arrays.equals(data, Files.toByteArray(temp))); try { Files.write(null, temp); fail("expected exception"); } catch (NullPointerException expected) { } }