use of java.util.Scanner in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method runFeatureWithStrictTestNGFormatter.
private String runFeatureWithStrictTestNGFormatter(CucumberFeature feature, Map<String, Result> stepsToResult, long stepDuration) throws IOException, Throwable, FileNotFoundException {
final File tempFile = File.createTempFile("cucumber-jvm-testng", ".xml");
final TestNGFormatter formatter = new TestNGFormatter(toURL(tempFile.getAbsolutePath()));
formatter.setStrict(true);
TestHelper.runFeatureWithFormatter(feature, stepsToResult, Collections.<SimpleEntry<String, Result>>emptyList(), stepDuration, formatter, formatter);
return new Scanner(new FileInputStream(tempFile), "UTF-8").useDelimiter("\\A").next();
}
use of java.util.Scanner in project ctci by careercup.
the class Question method findOpenNumber.
public static void findOpenNumber() throws FileNotFoundException {
Scanner in = new Scanner(new FileReader("Chapter 10/Question10_3/input_file_q10_3.txt"));
while (in.hasNextInt()) {
int n = in.nextInt();
/* Finds the corresponding number in the bitfield by using
* the OR operator to set the nth bit of a byte
* (e.g., 10 would correspond to the 2nd bit of index 2 in
* the byte array). */
bitfield[n / 8] |= 1 << (n % 8);
}
for (int i = 0; i < bitfield.length; i++) {
for (int j = 0; j < 8; j++) {
/* Retrieves the individual bits of each byte. When 0 bit
* is found, finds the corresponding value. */
if ((bitfield[i] & (1 << j)) == 0) {
System.out.println(i * 8 + j);
return;
}
}
}
}
use of java.util.Scanner in project learning-spark by databricks.
the class ChapterSixExample method loadCallSignTable.
static String[] loadCallSignTable() throws FileNotFoundException {
Scanner callSignTbl = new Scanner(new File("./files/callsign_tbl_sorted"));
ArrayList<String> callSignList = new ArrayList<String>();
while (callSignTbl.hasNextLine()) {
callSignList.add(callSignTbl.nextLine());
}
return callSignList.toArray(new String[0]);
}
use of java.util.Scanner in project AnimeTaste by daimajia.
the class PlaylistParser method parse.
/**
* See {@link Channels#newReader(java.nio.channels.ReadableByteChannel, String)}
* See {@link java.io.StringReader}
*
* @param source the source.
* @return a playlist.
* @throws ParseException parsing fails.
*/
public Playlist parse(Readable source) throws ParseException {
final Scanner scanner = new Scanner(source);
boolean firstLine = true;
int lineNumber = 0;
final List<Element> elements = new ArrayList<Element>(10);
final ElementBuilder builder = new ElementBuilder();
boolean endListSet = false;
int targetDuration = -1;
int mediaSequenceNumber = -1;
EncryptionInfo currentEncryption = null;
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (line.length() > 0) {
if (line.startsWith(EX_PREFIX)) {
if (firstLine) {
checkFirstLine(lineNumber, line);
firstLine = false;
} else if (line.startsWith(EXTINF)) {
parseExtInf(line, lineNumber, builder);
} else if (line.startsWith(EXT_X_ENDLIST)) {
endListSet = true;
} else if (line.startsWith(EXT_X_TARGET_DURATION)) {
if (targetDuration != -1) {
throw new ParseException(line, lineNumber, EXT_X_TARGET_DURATION + " duplicated");
}
targetDuration = parseTargetDuration(line, lineNumber);
} else if (line.startsWith(EXT_X_MEDIA_SEQUENCE)) {
if (mediaSequenceNumber != -1) {
throw new ParseException(line, lineNumber, EXT_X_MEDIA_SEQUENCE + " duplicated");
}
mediaSequenceNumber = parseMediaSequence(line, lineNumber);
} else if (line.startsWith(EXT_X_DISCONTINUITY)) {
builder.discontinuity(true);
} else if (line.startsWith(EXT_X_PROGRAM_DATE_TIME)) {
long programDateTime = parseProgramDateTime(line, lineNumber);
builder.programDate(programDateTime);
} else if (line.startsWith(EXT_X_KEY)) {
currentEncryption = parseEncryption(line, lineNumber);
} else {
log.log(Level.FINE, new StringBuilder().append("Unknown: '").append(line).append("'").toString());
}
} else if (line.startsWith(COMMENT_PREFIX)) {
// comment do nothing
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "----- Comment: " + line);
}
} else {
if (firstLine) {
checkFirstLine(lineNumber, line);
}
// No prefix: must be the media uri.
builder.encrypted(currentEncryption);
builder.uri(toURI(line));
elements.add(builder.create());
// a new element begins.
builder.reset();
}
}
lineNumber++;
}
return new Playlist(Collections.unmodifiableList(elements), endListSet, targetDuration, mediaSequenceNumber);
}
use of java.util.Scanner in project che by eclipse.
the class ProjectServiceTest method testMoveFileWithRenameAndOverwrite.
@Test
public void testMoveFileWithRenameAndOverwrite() throws Exception {
RegisteredProject myProject = pm.getProject("my_project");
myProject.getBaseFolder().createFolder("a/b/c");
// File names
String originFileName = "test.txt";
String destinationFileName = "overwriteMe.txt";
// File contents
String originContent = "to be or not no be";
String overwrittenContent = "that is the question";
((FolderEntry) myProject.getBaseFolder().getChild("a/b")).createFile(originFileName, originContent.getBytes(Charset.defaultCharset()));
((FolderEntry) myProject.getBaseFolder().getChild("a/b/c")).createFile(destinationFileName, overwrittenContent.getBytes(Charset.defaultCharset()));
Map<String, List<String>> headers = new HashMap<>();
headers.put(CONTENT_TYPE, singletonList(APPLICATION_JSON));
MoveOptions descriptor = DtoFactory.getInstance().createDto(MoveOptions.class);
descriptor.setName(destinationFileName);
descriptor.setOverWrite(true);
ContainerResponse response = launcher.service(POST, "http://localhost:8080/api/project/move/my_project/a/b/" + originFileName + "?to=/my_project/a/b/c", "http://localhost:8080/api", headers, DtoFactory.getInstance().toJson(descriptor).getBytes(Charset.defaultCharset()), null);
assertEquals(response.getStatus(), 201, "Error: " + response.getEntity());
assertEquals(response.getHttpHeaders().getFirst("Location"), URI.create("http://localhost:8080/api/project/file/my_project/a/b/c/" + destinationFileName));
// new
assertNotNull(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName));
Scanner inputStreamScanner = null;
String theFirstLineFromDestinationFile;
try {
inputStreamScanner = new Scanner(myProject.getBaseFolder().getChild("a/b/c/" + destinationFileName).getVirtualFile().getContent());
theFirstLineFromDestinationFile = inputStreamScanner.nextLine();
// destination should contain original file's content
assertEquals(theFirstLineFromDestinationFile, originContent);
} catch (ForbiddenException | ServerException e) {
Assert.fail(e.getMessage());
} finally {
if (inputStreamScanner != null) {
inputStreamScanner.close();
}
}
}
Aggregations