Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-10-30 23:11:51 -0400
committerSergey Prigogin2011-11-07 14:02:40 -0500
commit8da748eb55b53c22b4fafb788cd130d9e0e90776 (patch)
treed98e42e8f37806d8de1316075384ee472f6e9121 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite
parent5e8ca6778db6bd03182e018b1e6ea9bceba6dbca (diff)
downloadorg.eclipse.cdt-8da748eb55b53c22b4fafb788cd130d9e0e90776.tar.gz
org.eclipse.cdt-8da748eb55b53c22b4fafb788cd130d9e0e90776.tar.xz
org.eclipse.cdt-8da748eb55b53c22b4fafb788cd130d9e0e90776.zip
Cosmetics.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java38
1 files changed, 15 insertions, 23 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
index 6c8aaa8c51..8fc40a49d7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.util;
@@ -22,33 +22,29 @@ import org.eclipse.core.runtime.CoreException;
/**
* @author Emanuel Graf IFS
- *
*/
public class FileContentHelper {
-
- private static final int bufferSize = 512;
+ private static final int BUFFER_SIZE = 2048;
- public static String getContent(IFile file, int start) throws CoreException, IOException{
-
+ public static String getContent(IFile file, int start) throws CoreException, IOException {
InputStreamReader reader = getReaderForFile(file);
skip(start, reader);
final String rest = readRest(reader);
reader.close();
return rest;
-
}
public static String getContent(IFile file, int start, int length) {
try {
InputStreamReader r = getReaderForFile(file);
- char[] bytes = new char[length];
+ char[] chars = new char[length];
skip(start, r);
- read(length, r, bytes);
+ read(length, r, chars);
r.close();
- return new String(bytes);
+ return new String(chars);
} catch (IOException e) {
CCorePlugin.log(e);
} catch (CoreException e) {
@@ -60,29 +56,26 @@ public class FileContentHelper {
private static InputStreamReader getReaderForFile(IFile file)
throws CoreException, UnsupportedEncodingException {
InputStream contents = file.getContents();
- InputStreamReader r = new InputStreamReader(contents, file.getCharset());
- return r;
+ return new InputStreamReader(contents, file.getCharset());
}
- private static String readRest(InputStreamReader reader) throws IOException{
+ private static String readRest(InputStreamReader reader) throws IOException {
StringBuilder content = new StringBuilder();
- char[] buffer = new char[bufferSize];
+ char[] buffer = new char[BUFFER_SIZE];
int bytesRead = 0;
- while((bytesRead = reader.read(buffer)) >= 0){
+ while ((bytesRead = reader.read(buffer)) >= 0) {
content.append(buffer, 0, bytesRead);
}
-
return content.toString();
}
- private static void read(int length, InputStreamReader r, char[] bytes)
- throws IOException {
+ private static void read(int length, InputStreamReader r, char[] bytes) throws IOException {
int bufferOffset = 0;
int charactersRead = 0;
- while(charactersRead >= 0 && length > 0){
+ while (charactersRead >= 0 && length > 0) {
charactersRead = r.read(bytes, bufferOffset, length);
- if(charactersRead > 0){
+ if (charactersRead > 0) {
bufferOffset += charactersRead;
length -= charactersRead;
}
@@ -91,12 +84,11 @@ public class FileContentHelper {
private static void skip(int start, InputStreamReader r) throws IOException {
long skipped = 0;
- while(skipped >= 0 && start > 0 && r.ready()){
+ while (skipped >= 0 && start > 0 && r.ready()) {
skipped = r.skip(start);
- if(skipped > 0){
+ if (skipped > 0) {
start -= skipped;
}
}
}
-
}

Back to the top