Java Code Examples for java.io.LineNumberReader#ready()
The following examples show how to use
java.io.LineNumberReader#ready() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected boolean compareOutput(Reader expected, Reader actual) throws IOException { LineNumberReader expectedOutput = new LineNumberReader(expected); LineNumberReader actualOutput = new LineNumberReader(actual); while (expectedOutput.ready() && actualOutput.ready()) { String expectedLine = expectedOutput.readLine(); String actualLine = actualOutput.readLine(); if (!expectedLine.equals(actualLine)) { System.out.println("Entityreference expansion failed, line no: " + expectedOutput.getLineNumber()); System.out.println("Expected: " + expectedLine); System.out.println("Actual : " + actualLine); return false; } } expectedOutput.close(); actualOutput.close(); return true; }
Example 2
Source File: GlobalContext.java From drftpd with GNU General Public License v2.0 | 5 votes |
private static Properties getPropertiesUntilClosed(LineNumberReader reader) throws IOException { Properties p = new Properties(); String curLine; while (reader.ready()) { curLine = reader.readLine(); if (curLine != null) { curLine = curLine.trim(); if (curLine.startsWith("#") || curLine.equals("")) { // comment or blank line, ignore continue; } if (curLine.equals("}")) { // end of this block return p; } // internal loop int spaceIndex = curLine.indexOf(" "); if (spaceIndex == -1) { throw new FatalException("Line " + reader.getLineNumber() + " is not formatted properly"); } String propName = curLine.substring(0, spaceIndex); String value = curLine.substring(spaceIndex).trim(); String concatenate = p.getProperty(propName); if (concatenate == null) { p.put(propName, value); } else { p.put(propName, concatenate + "\n" + value); } } } throw new FatalException("Premature end of file, not enough \"}\" characters exist."); }
Example 3
Source File: GlobalContext.java From drftpd with GNU General Public License v2.0 | 5 votes |
private static Properties getPropertiesUntilClosed(LineNumberReader reader) throws IOException { Properties p = new Properties(); String curLine; while (reader.ready()) { curLine = reader.readLine(); if (curLine != null) { curLine = curLine.trim(); if (curLine.startsWith("#") || curLine.equals("")) { // comment or blank line, ignore continue; } if (curLine.equals("}")) { // end of this block return p; } // internal loop int spaceIndex = curLine.indexOf(" "); if (spaceIndex == -1) { throw new FatalException("Line " + reader.getLineNumber() + " is not formatted properly"); } String propName = curLine.substring(0, spaceIndex); String value = curLine.substring(spaceIndex).trim(); String concatenate = p.getProperty(propName); if (concatenate == null) { p.put(propName, value); } else { p.put(propName, concatenate + "\n" + value); } } } throw new FatalException("Premature end of file, not enough \"}\" characters exist."); }
Example 4
Source File: TestDockerContainerExecutorWithMocks.java From hadoop with Apache License 2.0 | 4 votes |
@Test public void testContainerLaunch() throws IOException { String appSubmitter = "nobody"; String appId = "APP_ID"; String containerId = "CONTAINER_ID"; String testImage = "\"sequenceiq/hadoop-docker:2.4.1\""; Container container = mock(Container.class, RETURNS_DEEP_STUBS); ContainerId cId = mock(ContainerId.class, RETURNS_DEEP_STUBS); ContainerLaunchContext context = mock(ContainerLaunchContext.class); HashMap<String, String> env = new HashMap<String,String>(); when(container.getContainerId()).thenReturn(cId); when(container.getLaunchContext()).thenReturn(context); when(cId.getApplicationAttemptId().getApplicationId().toString()).thenReturn(appId); when(cId.toString()).thenReturn(containerId); when(context.getEnvironment()).thenReturn(env); env.put(YarnConfiguration.NM_DOCKER_CONTAINER_EXECUTOR_IMAGE_NAME, testImage); Path scriptPath = new Path("file:///bin/echo"); Path tokensPath = new Path("file:///dev/null"); Path pidFile = new Path(workDir, "pid"); dockerContainerExecutor.activateContainer(cId, pidFile); int ret = dockerContainerExecutor.launchContainer( new ContainerStartContext.Builder() .setContainer(container) .setNmPrivateContainerScriptPath(scriptPath) .setNmPrivateTokensPath(tokensPath) .setUser(appSubmitter) .setAppId(appId) .setContainerWorkDir(workDir) .setLocalDirs(dirsHandler.getLocalDirs()) .setLogDirs(dirsHandler.getLogDirs()) .build()); assertEquals(0, ret); //get the script Path sessionScriptPath = new Path(workDir, Shell.appendScriptExtension( DockerContainerExecutor.DOCKER_CONTAINER_EXECUTOR_SESSION_SCRIPT)); LineNumberReader lnr = new LineNumberReader(new FileReader(sessionScriptPath.toString())); boolean cmdFound = false; List<String> localDirs = dirsToMount(dirsHandler.getLocalDirs()); List<String> logDirs = dirsToMount(dirsHandler.getLogDirs()); List<String> workDirMount = dirsToMount(Collections.singletonList(workDir.toUri().getPath())); List<String> expectedCommands = new ArrayList<String>( Arrays.asList(DOCKER_LAUNCH_COMMAND, "run", "--rm", "--net=host", "--name", containerId)); expectedCommands.addAll(localDirs); expectedCommands.addAll(logDirs); expectedCommands.addAll(workDirMount); String shellScript = workDir + "/launch_container.sh"; expectedCommands.addAll(Arrays.asList(testImage.replaceAll("['\"]", ""), "bash","\"" + shellScript + "\"")); String expectedPidString = "echo `/bin/true inspect --format {{.State.Pid}} " + containerId+"` > "+ pidFile.toString() + ".tmp"; boolean pidSetterFound = false; while(lnr.ready()){ String line = lnr.readLine(); LOG.debug("line: " + line); if (line.startsWith(DOCKER_LAUNCH_COMMAND)){ List<String> command = new ArrayList<String>(); for( String s :line.split("\\s+")){ command.add(s.trim()); } assertEquals(expectedCommands, command); cmdFound = true; } else if (line.startsWith("echo")) { assertEquals(expectedPidString, line); pidSetterFound = true; } } assertTrue(cmdFound); assertTrue(pidSetterFound); }
Example 5
Source File: TestDockerContainerExecutorWithMocks.java From big-c with Apache License 2.0 | 4 votes |
@Test public void testContainerLaunch() throws IOException { String appSubmitter = "nobody"; String appId = "APP_ID"; String containerId = "CONTAINER_ID"; String testImage = "\"sequenceiq/hadoop-docker:2.4.1\""; Container container = mock(Container.class, RETURNS_DEEP_STUBS); ContainerId cId = mock(ContainerId.class, RETURNS_DEEP_STUBS); ContainerLaunchContext context = mock(ContainerLaunchContext.class); HashMap<String, String> env = new HashMap<String,String>(); when(container.getContainerId()).thenReturn(cId); when(container.getLaunchContext()).thenReturn(context); when(cId.getApplicationAttemptId().getApplicationId().toString()).thenReturn(appId); when(cId.toString()).thenReturn(containerId); when(context.getEnvironment()).thenReturn(env); env.put(YarnConfiguration.NM_DOCKER_CONTAINER_EXECUTOR_IMAGE_NAME, testImage); Path scriptPath = new Path("file:///bin/echo"); Path tokensPath = new Path("file:///dev/null"); Path pidFile = new Path(workDir, "pid"); dockerContainerExecutor.activateContainer(cId, pidFile); int ret = dockerContainerExecutor.launchContainer(container, scriptPath, tokensPath, appSubmitter, appId, workDir, dirsHandler.getLocalDirs(), dirsHandler.getLogDirs()); assertEquals(0, ret); //get the script Path sessionScriptPath = new Path(workDir, Shell.appendScriptExtension( DockerContainerExecutor.DOCKER_CONTAINER_EXECUTOR_SESSION_SCRIPT)); LineNumberReader lnr = new LineNumberReader(new FileReader(sessionScriptPath.toString())); boolean cmdFound = false; List<String> localDirs = dirsToMount(dirsHandler.getLocalDirs()); List<String> logDirs = dirsToMount(dirsHandler.getLogDirs()); List<String> workDirMount = dirsToMount(Collections.singletonList(workDir.toUri().getPath())); List<String> expectedCommands = new ArrayList<String>( Arrays.asList(DOCKER_LAUNCH_COMMAND, "run", "--rm", "--net=host", "--name", containerId)); expectedCommands.addAll(localDirs); expectedCommands.addAll(logDirs); expectedCommands.addAll(workDirMount); String shellScript = workDir + "/launch_container.sh"; expectedCommands.addAll(Arrays.asList(testImage.replaceAll("['\"]", ""), "bash","\"" + shellScript + "\"")); String expectedPidString = "echo `/bin/true inspect --format {{.State.Pid}} " + containerId+"` > "+ pidFile.toString() + ".tmp"; boolean pidSetterFound = false; while(lnr.ready()){ String line = lnr.readLine(); LOG.debug("line: " + line); if (line.startsWith(DOCKER_LAUNCH_COMMAND)){ List<String> command = new ArrayList<String>(); for( String s :line.split("\\s+")){ command.add(s.trim()); } assertEquals(expectedCommands, command); cmdFound = true; } else if (line.startsWith("echo")) { assertEquals(expectedPidString, line); pidSetterFound = true; } } assertTrue(cmdFound); assertTrue(pidSetterFound); }