Java Examples for java.io.BufferedReader

The following java examples will help you to understand the usage of java.io.BufferedReader. These source code samples are taken from different open source projects.

Example 1
Project: schach-master  File: ListReader.java View source code
public static ArrayList<String> loadStrings(File aFile) {
    ArrayList<String> pVec = new ArrayList<String>();
    if (!aFile.exists())
        return pVec;
    try {
        BufferedReader pReader = new BufferedReader(new FileReader(aFile));
        String pLine;
        while ((pLine = pReader.readLine()) != null) {
            pLine = pLine.trim();
            if (pLine.startsWith("#") || pLine.equals(""))
                continue;
            pVec.add(pLine);
        }
        pReader.close();
    } catch (IOException aE) {
        aE.printStackTrace();
    }
    return pVec;
}
Example 2
Project: android-libcore64-master  File: BufferedReaderTest.java View source code
/**
	 * @tests java.io.BufferedReader#mark(int)
	 */
public void test_markI() throws IOException {
    // Test for method void java.io.BufferedReader.mark(int)
    char[] buf = null;
    br = new BufferedReader(new Support_StringReader(testString));
    br.skip(500);
    br.mark(1000);
    br.skip(250);
    br.reset();
    buf = new char[testString.length()];
    br.read(buf, 0, 500);
    assertTrue("Failed to set mark properly", testString.substring(500, 1000).equals(new String(buf, 0, 500)));
    try {
        br = new BufferedReader(new Support_StringReader(testString), 800);
        br.skip(500);
        br.mark(250);
        br.read(buf, 0, 1000);
        br.reset();
        fail("Failed to invalidate mark properly");
    } catch (IOException x) {
    }
    char[] chars = new char[256];
    for (int i = 0; i < 256; i++) chars[i] = (char) i;
    Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    in.skip(6);
    in.mark(14);
    in.read(new char[14], 0, 14);
    in.reset();
    assertTrue("Wrong chars", in.read() == (char) 6 && in.read() == (char) 7);
    in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    in.skip(6);
    in.mark(8);
    in.skip(7);
    in.reset();
    assertTrue("Wrong chars 2", in.read() == (char) 6 && in.read() == (char) 7);
    BufferedReader br = new BufferedReader(new StringReader("01234"), 2);
    br.mark(3);
    char[] carray = new char[3];
    int result = br.read(carray);
    assertEquals(3, result);
    assertEquals("Assert 0:", '0', carray[0]);
    assertEquals("Assert 1:", '1', carray[1]);
    assertEquals("Assert 2:", '2', carray[2]);
    assertEquals("Assert 3:", '3', br.read());
    br = new BufferedReader(new StringReader("01234"), 2);
    br.mark(3);
    carray = new char[4];
    result = br.read(carray);
    assertEquals("Assert 4:", 4, result);
    assertEquals("Assert 5:", '0', carray[0]);
    assertEquals("Assert 6:", '1', carray[1]);
    assertEquals("Assert 7:", '2', carray[2]);
    assertEquals("Assert 8:", '3', carray[3]);
    assertEquals("Assert 9:", '4', br.read());
    assertEquals("Assert 10:", -1, br.read());
    BufferedReader reader = new BufferedReader(new StringReader("01234"));
    reader.mark(Integer.MAX_VALUE);
    reader.read();
    reader.close();
}
Example 3
Project: ARTPart-master  File: BufferedReaderTest.java View source code
/**
	 * @tests java.io.BufferedReader#mark(int)
	 */
public void test_markI() throws IOException {
    // Test for method void java.io.BufferedReader.mark(int)
    char[] buf = null;
    br = new BufferedReader(new Support_StringReader(testString));
    br.skip(500);
    br.mark(1000);
    br.skip(250);
    br.reset();
    buf = new char[testString.length()];
    br.read(buf, 0, 500);
    assertTrue("Failed to set mark properly", testString.substring(500, 1000).equals(new String(buf, 0, 500)));
    try {
        br = new BufferedReader(new Support_StringReader(testString), 800);
        br.skip(500);
        br.mark(250);
        br.read(buf, 0, 1000);
        br.reset();
        fail("Failed to invalidate mark properly");
    } catch (IOException x) {
    }
    char[] chars = new char[256];
    for (int i = 0; i < 256; i++) chars[i] = (char) i;
    Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    in.skip(6);
    in.mark(14);
    in.read(new char[14], 0, 14);
    in.reset();
    assertTrue("Wrong chars", in.read() == (char) 6 && in.read() == (char) 7);
    in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    in.skip(6);
    in.mark(8);
    in.skip(7);
    in.reset();
    assertTrue("Wrong chars 2", in.read() == (char) 6 && in.read() == (char) 7);
    BufferedReader br = new BufferedReader(new StringReader("01234"), 2);
    br.mark(3);
    char[] carray = new char[3];
    int result = br.read(carray);
    assertEquals(3, result);
    assertEquals("Assert 0:", '0', carray[0]);
    assertEquals("Assert 1:", '1', carray[1]);
    assertEquals("Assert 2:", '2', carray[2]);
    assertEquals("Assert 3:", '3', br.read());
    br = new BufferedReader(new StringReader("01234"), 2);
    br.mark(3);
    carray = new char[4];
    result = br.read(carray);
    assertEquals("Assert 4:", 4, result);
    assertEquals("Assert 5:", '0', carray[0]);
    assertEquals("Assert 6:", '1', carray[1]);
    assertEquals("Assert 7:", '2', carray[2]);
    assertEquals("Assert 8:", '3', carray[3]);
    assertEquals("Assert 9:", '4', br.read());
    assertEquals("Assert 10:", -1, br.read());
    BufferedReader reader = new BufferedReader(new StringReader("01234"));
    reader.mark(Integer.MAX_VALUE);
    reader.read();
    reader.close();
}
Example 4
Project: android-sdk-sources-for-api-level-23-master  File: BufferedReaderTest.java View source code
/**
	 * @tests java.io.BufferedReader#mark(int)
	 */
public void test_markI() throws IOException {
    // Test for method void java.io.BufferedReader.mark(int)
    char[] buf = null;
    br = new BufferedReader(new Support_StringReader(testString));
    br.skip(500);
    br.mark(1000);
    br.skip(250);
    br.reset();
    buf = new char[testString.length()];
    br.read(buf, 0, 500);
    assertTrue("Failed to set mark properly", testString.substring(500, 1000).equals(new String(buf, 0, 500)));
    try {
        br = new BufferedReader(new Support_StringReader(testString), 800);
        br.skip(500);
        br.mark(250);
        br.read(buf, 0, 1000);
        br.reset();
        fail("Failed to invalidate mark properly");
    } catch (IOException x) {
    }
    char[] chars = new char[256];
    for (int i = 0; i < 256; i++) chars[i] = (char) i;
    Reader in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    in.skip(6);
    in.mark(14);
    in.read(new char[14], 0, 14);
    in.reset();
    assertTrue("Wrong chars", in.read() == (char) 6 && in.read() == (char) 7);
    in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
    in.skip(6);
    in.mark(8);
    in.skip(7);
    in.reset();
    assertTrue("Wrong chars 2", in.read() == (char) 6 && in.read() == (char) 7);
    BufferedReader br = new BufferedReader(new StringReader("01234"), 2);
    br.mark(3);
    char[] carray = new char[3];
    int result = br.read(carray);
    assertEquals(3, result);
    assertEquals("Assert 0:", '0', carray[0]);
    assertEquals("Assert 1:", '1', carray[1]);
    assertEquals("Assert 2:", '2', carray[2]);
    assertEquals("Assert 3:", '3', br.read());
    br = new BufferedReader(new StringReader("01234"), 2);
    br.mark(3);
    carray = new char[4];
    result = br.read(carray);
    assertEquals("Assert 4:", 4, result);
    assertEquals("Assert 5:", '0', carray[0]);
    assertEquals("Assert 6:", '1', carray[1]);
    assertEquals("Assert 7:", '2', carray[2]);
    assertEquals("Assert 8:", '3', carray[3]);
    assertEquals("Assert 9:", '4', br.read());
    assertEquals("Assert 10:", -1, br.read());
    BufferedReader reader = new BufferedReader(new StringReader("01234"));
    reader.mark(Integer.MAX_VALUE);
    reader.read();
    reader.close();
}
Example 5
Project: android-platform-tools-base-master  File: Main.java View source code
public static String getContent() {
    InputStream input = Main.class.getResourceAsStream("/first_pick.txt");
    if (input == null) {
        return "FAILED TO FIND first_pick.txt";
    }
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
        return reader.readLine();
    } catch (IOException e) {
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
            }
        }
    }
    return "FAILED TO READ CONTENT";
}
Example 6
Project: sonar-java-master  File: TryWithResourcesCheck.java View source code
void foo(String fileName) {
    FileReader fr = null;
    BufferedReader br = null;
    try {
        // Noncompliant [[sc=5;ec=8;secondary=9,10]] {{Change this "try" to a try-with-resources.}}
        fr = new FileReader(fileName);
        br = new BufferedReader(fr);
        return br.readLine();
    } catch (Exception e) {
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
            }
        }
        if (fr != null) {
            try {
                br.close();
            } catch (IOException e) {
            }
        }
    }
    try {
        // compliant, no finally block so let's rely on unclosed resource rule
        fr = new FileReader(fileName);
    } catch (Exception e) {
    }
    try (FileReader fr = new FileReader(fileName);
        BufferedReader br = new BufferedReader(fr)) {
        // compliant
        return br.readLine();
    } catch (Exception e) {
    }
}
Example 7
Project: jeql-master  File: IOUtil.java View source code
public static String readFile(String filename, boolean addEOL) throws IOException {
    StringBuffer buf = new StringBuffer();
    BufferedReader bufReader = null;
    try {
        FileInputStream fis = new FileInputStream(filename);
        bufReader = new BufferedReader(new InputStreamReader(fis));
        String line = "";
        while ((line = bufReader.readLine()) != null) {
            buf.append(line);
            // possibly add EOL char to each line
            if (addEOL)
                buf.append('\n');
        }
    // System.out.println(buf);
    } finally {
        if (bufReader != null)
            bufReader.close();
    }
    // may be empty string if an error occurred
    return buf.toString();
}
Example 8
Project: checkstyle-master  File: InputFinalInTryWithResource.java View source code
public static void test() {
    try {
    } catch (RuntimeException e) {
    }
    try (@NotNull BufferedReader br = new BufferedReader(new InputStreamReader(null, "utf-8"))) {
    } catch (IOException e) {
    }
    try (final BufferedReader br = new BufferedReader(new InputStreamReader(null, "utf-8"))) {
    } catch (IOException e) {
    }
    try (final BufferedReader br = new BufferedReader(new InputStreamReader(null, "utf-8"));
        final BufferedReader br2 = new BufferedReader(new InputStreamReader(null, "utf-8"))) {
    } catch (IOException e) {
    }
}
Example 9
Project: jeboorker-master  File: TextUtils.java View source code
public static StringBuilder removePageNumbers(String text) {
    StringBuilder result = new StringBuilder();
    try (BufferedReader textReader = new BufferedReader(new StringReader(text))) {
        String line;
        for (int i = 1; (line = trim(textReader.readLine())) != null; ) {
            int num = NumberUtils.toInt(line, -1);
            if (num == i) {
                i++;
                continue;
            }
            result.append(line).append(StringUtil.NEW_LINE);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return result;
}
Example 10
Project: ocr-tools-master  File: OptionsReader.java View source code
public static String getLanguages() throws FileNotFoundException, IOException {
    InputStream propsStream = OptionsReader.class.getClassLoader().getResourceAsStream("languages.properties");
    BufferedReader r = new BufferedReader(new InputStreamReader(propsStream));
    String langs = "";
    String[] keyValue = r.readLine().split("\\s*=\\s*");
    langs += "<option selected=\"selected\" value=\"" + keyValue[0] + "\">" + keyValue[1] + "</option>\n";
    String line = "";
    while ((line = r.readLine()) != null) {
        keyValue = line.split("\\s*=\\s*");
        if (keyValue.length == 2) {
            langs += "<option value=\"" + keyValue[0] + "\">" + keyValue[1] + "</option>\n";
        }
    }
    return langs;
}
Example 11
Project: extFM-Tooling-master  File: MtextDebugCommunicationHelper.java View source code
/**
	 * Sends a message using the given stream and waits for an answer.
	 * 
	 * @param messageType the type of message to send
	 * @param stream the stream to send the message to
	 * @param reader the reader to obtain the answer from
	 * @param parameters additional parameter to send
	 * 
	 * @return the answer that is received
	 */
public org.feature.multi.perspective.mapping.viewmapping.resource.mtext.debug.MtextDebugMessage sendAndReceive(org.feature.multi.perspective.mapping.viewmapping.resource.mtext.debug.MtextDebugMessage message, java.io.PrintStream stream, java.io.BufferedReader reader) {
    synchronized (stream) {
        sendEvent(message, stream);
        org.feature.multi.perspective.mapping.viewmapping.resource.mtext.debug.MtextDebugMessage response = receive(reader);
        return response;
    }
}
Example 12
Project: open-mika-master  File: BufferedReaderTest.java View source code
/**
     * @tests java.io.BufferedReader#read(char[], int, int)
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Checks exceptions.",
        method = "read",
        args = {char[].class, int.class, int.class}
    )
     */
public void test_read$CII() throws IOException {
    char[] in = { 'L', 'o', 'r', 'e', 'm' };
    char[] ch = new char[3];
    BufferedReader reader = new BufferedReader(new CharArrayReader(in));
    try {
        reader.read(null, 1, 0);
        fail("Test 1: NullPointerException expected.");
    } catch (NullPointerException e) {
    }
    try {
        reader.read(ch, -1, 1);
        fail("Test 2: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
        reader.read(ch, 1, -1);
        fail("Test 3: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    }
    try {
        reader.read(ch, 1, 3);
        fail("Test 4: IndexOutOfBoundsException expected.");
    } catch (IndexOutOfBoundsException e) {
    }
    reader.close();
    try {
        reader.read(ch, 1, 1);
        fail("Test 5: IOException expected.");
    } catch (IOException e) {
    }
}
Example 13
Project: Mint-Programming-Language-master  File: ExecuteJava.java View source code
@Override
public Pointer apply(SmartList<Pointer> args) throws MintException {
    String programName = PointerTools.dereferenceString(args.get(0));
    programName = programName.trim();
    String className = programName.replace(".java", "");
    if (!programName.endsWith(".java")) {
        programName += ".java";
    }
    try {
        Process jv = Runtime.getRuntime().exec("javac " + programName);
        Process jv2 = Runtime.getRuntime().exec("java " + className);
        BufferedReader in = new BufferedReader(new InputStreamReader(jv2.getInputStream()));
        String line = null;
        int i = 0;
        int limit = Integer.MAX_VALUE >>> 1;
        while (i < limit) {
            line = in.readLine();
            if (line == null) {
                break;
            }
            System.out.println(line);
            i++;
        }
    } catch (IOException ex) {
    }
    return Constants.MINT_NULL;
}
Example 14
Project: MyDownload-master  File: Utils.java View source code
public static String getRawData(String string) {
    String dataString = "";
    try {
        URL url;
        url = new URL(string);
        URLConnection conn = url.openConnection();
        // conn.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        byte buffer[] = new byte[1024];
        String readerString;
        while ((readerString = reader.readLine()) != null) {
            dataString += readerString;
        }
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
        log("IOException", "" + e);
    }
    log("getRawData", dataString);
    return dataString;
}
Example 15
Project: nptornews-master  File: FileUtils.java View source code
public static CharSequence readFile(Resources resources, int id) {
    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(resources.openRawResource(id)), 8192);
        String line;
        StringBuilder buffer = new StringBuilder();
        while ((line = in.readLine()) != null) {
            buffer.append(line).append('\n');
        }
        // Chomp the last newline
        if (buffer.length() > 0) {
            buffer.deleteCharAt(buffer.length() - 1);
        }
        return buffer;
    } catch (IOException e) {
        return "";
    } finally {
        closeStream(in);
    }
}
Example 16
Project: liferay-ide-master  File: CompareFileHandler.java View source code
protected File getTemplateFile(IFile currentFile) throws Exception {
    final IProject currentProject = currentFile.getProject();
    final IFile bndfile = currentProject.getFile("bnd.bnd");
    File templateFile = null;
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(bndfile.getContents()))) {
        String fragment;
        while ((fragment = reader.readLine()) != null) {
            if (fragment.startsWith("Fragment-Host:")) {
                fragment = fragment.substring(fragment.indexOf(":") + 1, fragment.indexOf(";")).trim();
                break;
            }
        }
        final String hookfolder = currentFile.getFullPath().toOSString().substring(currentFile.getFullPath().toOSString().lastIndexOf("META-INF"));
        final IPath templateLocation = GradleCore.getDefault().getStateLocation().append(fragment).append(hookfolder);
        templateFile = new File(templateLocation.toOSString());
        if (!templateFile.exists()) {
            throw new FileNotFoundException("Template not found.");
        }
    }
    return templateFile;
}
Example 17
Project: JPaxos-master  File: BarrierClient.java View source code
public void enterBarrier(String host, int port, int requests, long time, int number) {
    try {
        Socket skt = new Socket(host, port);
        // System.out.println("# " + requests + " " + time);
        DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(skt.getOutputStream()));
        dos.writeInt(number);
        dos.writeInt(requests);
        dos.writeLong(time);
        dos.flush();
        BufferedReader in = new BufferedReader(new InputStreamReader(skt.getInputStream()));
        while (!in.ready()) {
        }
        in.readLine();
        in.close();
        dos.close();
        skt.close();
    } catch (Exception e) {
        System.out.print("Whoops! It didn't work!\n");
        System.exit(1);
    }
}
Example 18
Project: traffic-balance-master  File: JSONRPCSkeleton.java View source code
void processRequest(BufferedReader in, PrintWriter out) {
    JSONObject jsonResponse = new JSONObject();
    try {
        JSONObject jsonRequest = new JSONObject(in.readLine());
        String methodName = jsonRequest.getString(JSONRPCConstants.METHOD_KEY);
        JSONArray params = jsonRequest.getJSONArray(JSONRPCConstants.PARAMS_KEY);
        JSONObject result = invoke(methodName, params);
        jsonResponse.put(JSONRPCConstants.RESULT_KEY, result);
    } catch (Exception ex) {
        try {
            jsonResponse.put(JSONRPCConstants.ERROR_KEY, ex.getMessage());
        } catch (JSONException e) {
            throw new RuntimeException("Error while creating response", e);
        }
    }
    out.println(jsonResponse.toString());
}
Example 19
Project: trie4j-master  File: GenHtml.java View source code
public static void main(String[] args) throws Exception {
    String templ = null;
    InputStream temps = GenHtml.class.getResourceAsStream("template.txt");
    try {
        templ = StreamUtil.readAsString(temps, "UTF-8");
    } finally {
        temps.close();
    }
    InputStream res = GenHtml.class.getResourceAsStream("result.txt");
    try {
        BufferedReader r = new BufferedReader(new InputStreamReader(res, "UTF-8"));
        String line = null;
        while ((line = r.readLine()) != null) {
            String[] vals = line.split("[ ]+");
            String name = vals[0].substring(0, vals[0].length() - 1).replaceAll("\\(", "\\\\(").replaceAll("\\)", "\\\\)").trim();
            templ = templ.replaceAll("\\$\\{" + name + "\\.build\\}", String.format("%,d", Integer.valueOf(vals[1].replace(',', ' ').trim()))).replaceAll("\\$\\{" + name + "\\.contains\\}", String.format("%,d", Integer.valueOf(vals[2].replace(',', ' ').trim()))).replaceAll("\\$\\{" + name + "\\.mem\\}", String.format("%.1f", Integer.valueOf(vals[3].replace(',', ' ').trim()) / 1000000.0));
        }
        System.out.println(templ);
    } finally {
        res.close();
    }
}
Example 20
Project: vlc-android-macbuild-master  File: StreamHelper.java View source code
public static String readStreamLineByLine(InputStream inputStream) {
    InputStreamReader reader = new InputStreamReader(inputStream);
    BufferedReader buffReader = new BufferedReader(reader);
    StringBuilder text = new StringBuilder();
    String resultText = null;
    try {
        String line;
        while ((line = buffReader.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
        resultText = text.toString();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            buffReader.close();
            reader.close();
        } catch (Exception e) {
        }
    }
    return resultText;
}
Example 21
Project: SecurePhoto-master  File: SecurePhotoBaseTests.java View source code
@Test(timeout = 10000)
public void testServerConnectivity() throws Exception {
    Socket clientSocket = null;
    PrintWriter outWriter = null;
    BufferedReader inReader = null;
    String response = null;
    try {
        clientSocket = new Socket("localhost", SPConstants.SERVER_DEFAULT_PORT);
        outWriter = new PrintWriter(clientSocket.getOutputStream(), true);
        inReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        outWriter.println("Testing connectivity");
        response = inReader.readLine();
    } catch (IOException e) {
        throw new Exception("Exception during writing to socket: " + e.getMessage());
    }
    Assert.assertEquals(SPConstants.SERVER_OK_MESSAGE, response);
}
Example 22
Project: tmdm-studio-se-master  File: TestUtil.java View source code
/**
     * Used to read test resource
     * 
     * @param fileName
     * @return
     * @throws Exception
     */
public static String readTestResource(Class cls, String fileName) throws Exception {
    InputStreamReader fr = null;
    BufferedReader br = null;
    try {
        InputStream inputStream = cls.getResourceAsStream(fileName);
        fr = new InputStreamReader(inputStream);
        br = new BufferedReader(fr);
        StringBuffer buffer = new StringBuffer();
        String tmpStr;
        while ((tmpStr = br.readLine()) != null) {
            buffer.append(tmpStr);
        }
        return buffer.toString();
    } finally {
        if (br != null) {
            br.close();
        }
        if (fr != null) {
            fr.close();
        }
    }
}
Example 23
Project: ldbc_snb_datagen-master  File: EmpiricalDistribution.java View source code
@Override
public ArrayList<Bucket> getBuckets(Configuration conf) {
    fileName = conf.get("ldbc.snb.datagen.generator.distribution.EmpiricalDistribution.fileName");
    ArrayList<Pair<Integer, Integer>> histogram = new ArrayList<Pair<Integer, Integer>>();
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(fileName), "UTF-8"));
        String line;
        while ((line = reader.readLine()) != null) {
            String data[] = line.split(" ");
            histogram.add(new Pair<Integer, Integer>(Integer.parseInt(data[0]), Integer.parseInt(data[1])));
        }
        reader.close();
        return Bucket.bucketizeHistogram(histogram, 1000);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Example 24
Project: Tank-master  File: CustomInputStream.java View source code
public static File getNewFile(File file) throws IOException {
    FileReader fr = new FileReader(file);
    BufferedReader br = new BufferedReader(fr);
    List<String> contents = new ArrayList<String>();
    String s;
    int i = 0;
    while ((s = br.readLine()) != null) {
        contents.add(s);
        if (s.endsWith(">")) {
            if (i == 0) {
                contents.add(startTag);
            }
            i++;
        }
    }
    contents.add(endTag);
    br.close();
    fr.close();
    File tmpFile = File.createTempFile("temporary", ".xml");
    FileWriter fw = new FileWriter(tmpFile);
    BufferedWriter bw = new BufferedWriter(fw);
    for (String string : contents) {
        bw.write(string);
        System.out.println(string);
    }
    bw.close();
    fw.close();
    return tmpFile;
}
Example 25
Project: Desktop-master  File: ZoteroAnnoteFieldRemoverAction.java View source code
@Override
public void performAction(File file) {
    StringBuffer sb = new StringBuffer();
    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            if (line.trim().startsWith("annote = {")) {
                while (!line.endsWith("},") && !line.endsWith("}")) {
                    line = br.readLine();
                }
            } else {
                sb.append(line);
                sb.append("\r\n");
            }
        }
        br.close();
        FileWriter fw = new FileWriter(file);
        fw.write(sb.toString());
        fw.close();
    } catch (IOException e) {
        DocearLogger.error(e);
    }
}