Search in sources :

Example 16 with Scanner

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();
}
Also used : Scanner(java.util.Scanner) File(java.io.File) FileInputStream(java.io.FileInputStream) Result(gherkin.formatter.model.Result)

Example 17 with Scanner

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;
            }
        }
    }
}
Also used : Scanner(java.util.Scanner) FileReader(java.io.FileReader)

Example 18 with Scanner

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]);
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) File(java.io.File)

Example 19 with Scanner

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);
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList)

Example 20 with Scanner

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();
        }
    }
}
Also used : Scanner(java.util.Scanner) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ContainerResponse(org.everrest.core.impl.ContainerResponse) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) Test(org.testng.annotations.Test)

Aggregations

Scanner (java.util.Scanner)567 File (java.io.File)97 IOException (java.io.IOException)63 NoSuchElementException (java.util.NoSuchElementException)59 ArrayList (java.util.ArrayList)56 Test (org.junit.Test)53 InputStream (java.io.InputStream)51 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 InputMismatchException (java.util.InputMismatchException)47 FileNotFoundException (java.io.FileNotFoundException)42 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 FileInputStream (java.io.FileInputStream)27 HashMap (java.util.HashMap)26 Locale (java.util.Locale)23 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)18 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)18