Example usage for java.io LineNumberReader close

List of usage examples for java.io LineNumberReader close

Introduction

In this page you can find the example usage for java.io LineNumberReader close.

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:com.l2jfree.gameserver.handler.admincommands.AdminTeleport.java

private void delbookmark(String Name) {
    File file = new File(Config.DATAPACK_ROOT, "data/html/admin/tele/bookmark.txt");
    LineNumberReader lnr = null;
    String bookmarks = "";

    try {/*from w  ww .j a v  a 2 s. c o m*/
        String line = null;
        lnr = new LineNumberReader(new FileReader(file));
        while ((line = lnr.readLine()) != null) {
            StringTokenizer st = new StringTokenizer(line, ";");
            String nm = st.nextToken();
            if (!nm.equals(Name))
                bookmarks += line + "\n";
        }

        FileWriter save = new FileWriter(file);
        save.write(bookmarks);
        save.close();
    } catch (FileNotFoundException e) {
    } catch (IOException e1) {
        e1.printStackTrace();
    } finally {
        try {
            if (lnr != null)
                lnr.close();
        } catch (Exception e2) {
        }
    }
}

From source file:com.smartgwt.extensions.fileuploader.server.TestServiceImpl.java

/**
 * This files a test file that contains a response for all CRUD operations. See example
 * profile.xq.xml file./*from  w  w  w  . j a v a 2 s.c  o m*/
 * @param out
 * @param context
 * @param model
 * @param xq
 * @param op
 * @throws Exception
 */
private void getResponse(PrintWriter out, String context, String model, String xq, String op) throws Exception {
    String path = "src/test/webapp/WEB-INF/models/" + model + "/" + xq + ".xml";
    System.out.println("getting datafile " + path);
    LineNumberReader in = null;
    File f = new File(path);
    if (!f.exists()) {
        System.out.println("File not found:" + path);
        out.println("<response>");
        out.println("  <status>1</status");
        out.println("</response>");
        return;
    }
    try {
        String start = "<" + op + ">";
        String end = "</" + op + ">";
        in = new LineNumberReader(new FileReader(f));
        String line = null;
        boolean inOp = false;
        while ((line = in.readLine()) != null) {
            if (line.indexOf(start) > 0)
                inOp = true;
            else if (line.indexOf(end) > 0)
                inOp = false;
            else if (inOp)
                out.println(line);
            //System.out.println(line);
        }
    } catch (FileNotFoundException fnf) {
        throw new Exception(fnf);
    } finally {
        if (in != null)
            try {
                in.close();
            } catch (Exception e) {
            }
        ;
    }
}

From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java

protected String readCode(DesignMetadata md) throws FileNotFoundException, IOException, WGDesignSyncException,
        InstantiationException, IllegalAccessException {

    // No, filecontainers have no code, but thanks for asking....
    if (getType() == WGDocument.TYPE_FILECONTAINER) {
        return null;
    }//from  w ww. j av  a 2s  .  c o  m

    FileObject codeFile = getCodeFile();
    if (!codeFile.exists()) {
        throw new WGDesignSyncException("Code of file '" + getCodeFile().getName().getPath()
                + "' could not be read because the file does not exist.");
    }

    LineNumberReader reader = new LineNumberReader(createReader(codeFile));
    StringWriter writer = new StringWriter();
    int headerLines = 0;
    try {
        String line;
        boolean lookForHeaders = true;
        boolean firstLine = true;

        while ((line = reader.readLine()) != null) {
            if (lookForHeaders == true && line.startsWith("##")) {
                processDesignHeader(line, md.getInfo());
                headerLines++;
            } else {
                lookForHeaders = false;

                if (!firstLine) {
                    writer.write("\n");
                } else {
                    firstLine = false;
                }

                writer.write(line);
            }
        }
    } finally {
        reader.close();
        codeFile.getContent().close();
    }
    writer.close();
    md.setHeaderLines(headerLines);
    String code = writer.toString();
    return code;
}

From source file:com.l2jfree.gameserver.geodata.pathfinding.geonodes.GeoPathFinding.java

private GeoPathFinding() {
    LineNumberReader lnr = null;
    try {/*from  w  ww.  j  av a 2 s  . co m*/
        _log.info("PathFinding Engine: - Loading Path Nodes...");
        File Data = new File("./data/pathnode/pn_index.txt");
        if (!Data.exists())
            return;

        lnr = new LineNumberReader(new BufferedReader(new FileReader(Data)));
    } catch (Exception e) {
        throw new Error("Failed to Load pn_index File.", e);
    }
    String line;
    try {
        while ((line = lnr.readLine()) != null) {
            if (line.trim().length() == 0)
                continue;
            StringTokenizer st = new StringTokenizer(line, "_");
            byte rx = Byte.parseByte(st.nextToken());
            byte ry = Byte.parseByte(st.nextToken());
            LoadPathNodeFile(rx, ry);
        }
    } catch (Exception e) {
        throw new Error("Failed to Read pn_index File.", e);
    } finally {
        try {
            lnr.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.tolweb.content.preparers.EolContentPreparer.java

private List<String> createReferencesList(MappedPage mpage) {
    List<String> references = new ArrayList<String>();
    String input = mpage.getReferences();

    if (input != null) {
        LineNumberReader reader = null;
        String currentLine;//from  w w  w.  j ava2 s  .  co m
        try {
            reader = new LineNumberReader(new StringReader(input));
            while ((currentLine = reader.readLine()) != null) {
                if (StringUtils.notEmpty(currentLine)) {
                    references.add(currentLine);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (Exception e) {
            }
        }
    }
    return references;
}

From source file:codingchallenge.SortableChallenge.java

private void initProductsMatcher() throws IOException, JSONException {
    List<Product> products = new ArrayList<Product>();
    LineNumberReader lproductsReader = new LineNumberReader(productsReader);
    try {/* w w  w.  j  a v a  2s. c  om*/
        for (String line = lproductsReader.readLine(); line != null; line = lproductsReader.readLine()) {
            line = line.trim();
            if (line.length() == 0) {
                continue;
            }
            JSONTokener tokener = new JSONTokener(line);
            Object token = tokener.nextValue();
            if (!(token instanceof JSONObject)) {
                throw new BadInputException("Bad product data: " + token);
            }
            JSONObject productJSON = (JSONObject) token;
            String name = getStringProp("product_name", productJSON);
            String manufacturer = getStringProp("manufacturer", productJSON);
            String family = getStringProp("family", productJSON);
            String model = getStringProp("model", productJSON);
            String announcedDate = getStringProp("announced-date", productJSON);
            products.add(new Product(name, manufacturer, family, model, announcedDate));
        }
    } finally {
        lproductsReader.close();
    }
    matcher.initProducts(products);

}

From source file:eu.qualimaster.coordination.profiling.SimpleParser.java

/**
 * Parses the control file.//w  w  w  .j  a va2s . c o m
 * 
 * @param file the file to read
 * @param considerImport whether imports shall be considered or ignored
 * @param profile the profile to be built
 * @return the actual data file (from {@link IProfile#getDataFile()} if not changed by imports)
 * @throws IOException if loading/parsing the control file fails
 */
private ParseResult parseControlFile(File file, boolean considerImport, IProfile profile) throws IOException {
    ParseResult result = new ParseResult();
    List<Integer> tmpTasks = new ArrayList<Integer>();
    List<Integer> tmpExecutors = new ArrayList<Integer>();
    List<Integer> tmpWorkers = new ArrayList<Integer>();
    result.addDataFile(profile.getDataFile());
    addDataFiles(profile.getDataFile().getParentFile(), result, profile, false);
    if (file.exists()) {
        LineNumberReader reader = new LineNumberReader(new FileReader(file));
        String line;
        do {
            line = reader.readLine();
            if (null != line) {
                line = line.trim();
                if (line.startsWith(IMPORT)) {
                    if (considerImport) {
                        handleImport(line, result, profile);
                    }
                } else if (line.startsWith(PROCESSING)) {
                    line = line.substring(PROCESSING.length()).trim();
                    parseList(line, TASKS, tmpTasks, INT_HELPER);
                    parseList(line, EXECUTORS, tmpExecutors, INT_HELPER);
                    parseList(line, WORKERS, tmpWorkers, INT_HELPER);
                } else if (line.startsWith(PARAMETER)) {
                    line = line.substring(PARAMETER.length()).trim();
                    parseParameter(line, profile, result);
                }
            }
        } while (null != line);
        reader.close();
    }
    result.merge(tmpTasks, tmpExecutors, tmpWorkers);
    return result;
}

From source file:fitnesserefactor.FitnesseRefactor.java

public int CountLines(File filename) throws FileNotFoundException, IOException {
    LineNumberReader reader = new LineNumberReader(new FileReader(filename));
    int cnt = 0;/*from   w  w  w .  j  a  va  2  s .  co  m*/
    String lineRead = "";
    while ((lineRead = reader.readLine()) != null) {
    }
    cnt = reader.getLineNumber();
    reader.close();
    return cnt;
}

From source file:org.apache.isis.objectstore.nosql.db.file.server.FileServer.java

private void recover(final File file) {
    LineNumberReader reader = null;
    try {//from  w ww  .  j a  v  a  2  s  . c  o  m
        reader = new LineNumberReader(new InputStreamReader(new FileInputStream(file), Util.ENCODING));

        while (true) {
            final String line = reader.readLine();
            if (line == null) {
                break;
            }
            if (!line.startsWith("#transaction started")) {
                throw new NoSqlStoreException(
                        "No transaction start found: " + line + " (" + reader.getLineNumber() + ")");
            }
            readTransaction(reader);
        }
    } catch (final IOException e) {
        throw new NoSqlStoreException(e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (final IOException e) {
                throw new NoSqlStoreException(e);
            }
        }
    }
}

From source file:org.kuali.test.proxyserver.MultiPartHandler.java

public MultiPartHandler(MultipartStream multipartStream) throws IOException {
    LineNumberReader lnr = null;
    try {/*w  w w . j  a v  a 2  s  .c  o  m*/
        lnr = new LineNumberReader(new StringReader(multipartStream.readHeaders()));
        String line;

        while ((line = lnr.readLine()) != null) {
            if (line.startsWith(Constants.CONTENT_DISPOSITION)) {
                for (String param : PARAMETER_NAMES) {
                    int pos = line.indexOf(param);
                    if (pos > -1) {
                        pos += (param.length() + 2);
                        int pos2 = line.indexOf("\"", pos);

                        if ((pos > -1) && (pos2 > -1) && (pos2 > pos)) {
                            parameters.put(param, line.substring(pos, pos2));
                        }
                    }
                }
            }

            if (line.startsWith(Constants.HTTP_RESPONSE_CONTENT_TYPE)) {
                int pos = line.indexOf(Constants.SEPARATOR_COLON);

                if (pos > -1) {
                    contentType = line.substring(pos + 1).trim();
                }
            }
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
        multipartStream.readBodyData(bos);
        bytes = bos.toByteArray();
    }

    finally {
        try {
            if (lnr != null) {
                lnr.close();
            }
        }

        catch (Exception ex) {
        }
        ;
    }
}