Search in sources :

Example 1 with LineProcessor

use of com.google.common.io.LineProcessor in project GeoGig by boundlessgeo.

the class JEStagingDatabase method getConflict.

/**
     * Gets the specified conflict from the database.
     * 
     * @param namespace the namespace of the conflict
     * @param path the conflict to retrieve
     * @return the conflict, or {@link Optional#absent()} if it was not found
     */
@Override
public Optional<Conflict> getConflict(@Nullable String namespace, final String path) {
    final Object monitor = resolveConflictsMonitor(namespace);
    if (null == monitor) {
        return Optional.absent();
    }
    synchronized (monitor) {
        File file = resolveConflictsFile(namespace);
        if (file == null || !file.exists()) {
            return Optional.absent();
        }
        Conflict conflict = null;
        try {
            conflict = Files.readLines(file, Charsets.UTF_8, new LineProcessor<Conflict>() {

                Conflict conflict = null;

                @Override
                public Conflict getResult() {
                    return conflict;
                }

                @Override
                public boolean processLine(String s) throws IOException {
                    Conflict c = Conflict.valueOf(s);
                    if (c.getPath().equals(path)) {
                        conflict = c;
                        return false;
                    } else {
                        return true;
                    }
                }
            });
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        return Optional.fromNullable(conflict);
    }
}
Also used : Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) IOException(java.io.IOException) LineProcessor(com.google.common.io.LineProcessor) File(java.io.File)

Example 2 with LineProcessor

use of com.google.common.io.LineProcessor in project j2objc by google.

the class ProGuardUsageParser method parse.

public static CodeReferenceMap parse(CharSource listing) throws IOException {
    LineProcessor<CodeReferenceMap> processor = new LineProcessor<CodeReferenceMap>() {

        CodeReferenceMap.Builder dead = CodeReferenceMap.builder();

        String lastClass;

        @Override
        public CodeReferenceMap getResult() {
            return dead.build();
        }

        private void handleClass(String line) {
            if (line.endsWith(":")) {
                // Class, but not completely dead; save to read its dead methods
                lastClass = line.substring(0, line.length() - 1);
            } else {
                dead.addClass(line);
            }
        }

        private void handleMethod(String line) throws IOException {
            Matcher methodMatcher = proGuardMethodPattern.matcher(line);
            if (!methodMatcher.matches()) {
                throw new AssertionError("Line doesn't match expected ProGuard format!");
            }
            if (lastClass == null) {
                throw new IOException("Bad listing format: method not attached to a class");
            }
            String returnType = methodMatcher.group(5);
            String methodName = methodMatcher.group(6);
            String arguments = methodMatcher.group(7);
            String signature = buildMethodSignature(returnType, arguments);
            dead.addMethod(lastClass, methodName, signature);
        }

        private void handleField(String line) throws IOException {
            String name = line.substring(line.lastIndexOf(" ") + 1);
            dead.addField(lastClass, name);
        }

        @Override
        public boolean processLine(String line) throws IOException {
            if (line.startsWith("ProGuard, version") || line.startsWith("Reading ")) {
            // ignore output header
            } else if (!line.startsWith("    ")) {
                handleClass(line);
            } else if (line.startsWith("    ") && !line.contains("(")) {
                handleField(line);
            } else {
                handleMethod(line);
            }
            return true;
        }
    };
    return listing.readLines(processor);
}
Also used : Matcher(java.util.regex.Matcher) IOException(java.io.IOException) LineProcessor(com.google.common.io.LineProcessor)

Example 3 with LineProcessor

use of com.google.common.io.LineProcessor in project GeoGig by boundlessgeo.

the class JEStagingDatabase method getConflicts.

/**
     * Gets all conflicts that match the specified path filter.
     * 
     * @param namespace the namespace of the conflict
     * @param pathFilter the path filter, if this is not defined, all conflicts will be returned
     * @return the list of conflicts
     */
@Override
public List<Conflict> getConflicts(@Nullable String namespace, @Nullable final String pathFilter) {
    final Object monitor = resolveConflictsMonitor(namespace);
    if (null == monitor) {
        return ImmutableList.of();
    }
    synchronized (monitor) {
        final File file = resolveConflictsFile(namespace);
        if (null == file || !file.exists() || file.length() == 0) {
            return ImmutableList.of();
        }
        List<Conflict> conflicts;
        try {
            conflicts = Files.readLines(file, Charsets.UTF_8, new LineProcessor<List<Conflict>>() {

                List<Conflict> conflicts = Lists.newArrayList();

                @Override
                public List<Conflict> getResult() {
                    return conflicts;
                }

                @Override
                public boolean processLine(String s) throws IOException {
                    Conflict c = Conflict.valueOf(s);
                    if (pathFilter == null) {
                        conflicts.add(c);
                    } else if (c.getPath().startsWith(pathFilter)) {
                        conflicts.add(c);
                    }
                    return true;
                }
            });
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        return conflicts;
    }
}
Also used : Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) LineProcessor(com.google.common.io.LineProcessor) File(java.io.File)

Example 4 with LineProcessor

use of com.google.common.io.LineProcessor in project GeoGig by boundlessgeo.

the class ReadOSMLogEntries method _call.

@Override
protected List<OSMLogEntry> _call() {
    URL url = command(ResolveOSMLogfile.class).call();
    File file = new File(url.getFile());
    List<OSMLogEntry> entries;
    try {
        synchronized (file.getCanonicalPath().intern()) {
            entries = Files.readLines(file, Charsets.UTF_8, new LineProcessor<List<OSMLogEntry>>() {

                List<OSMLogEntry> entries = Lists.newArrayList();

                @Override
                public List<OSMLogEntry> getResult() {
                    return entries;
                }

                @Override
                public boolean processLine(String s) throws IOException {
                    OSMLogEntry entry = OSMLogEntry.valueOf(s);
                    entries.add(entry);
                    return true;
                }
            });
        }
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return entries;
}
Also used : List(java.util.List) IOException(java.io.IOException) LineProcessor(com.google.common.io.LineProcessor) File(java.io.File) URL(java.net.URL)

Aggregations

LineProcessor (com.google.common.io.LineProcessor)4 IOException (java.io.IOException)4 File (java.io.File)3 List (java.util.List)2 Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)2 ImmutableList (com.google.common.collect.ImmutableList)1 URL (java.net.URL)1 Matcher (java.util.regex.Matcher)1