public char[] getContents() { if (this.contents != null) return this.contents; // answer the cached source // otherwise retrieve it try { return Util.getFileCharContent(new File(new String(this.fileName)), this.encoding); } catch (IOException e) { // could not read file: returns an empty array } return CharOperation.NO_CHAR; } /**
/** * Search the line number corresponding to a specific position * @param position int * @return int */ @Override public final int getLineNumber(int position) { return Util.getLineNumber(position, this.lineEnds, 0, this.linePtr); } @Override
private char[] readSource(ZipEntry entry, ZipFile zip, String charSet) { try { byte[] bytes = Util.getZipEntryByteContent(entry, zip); if (bytes != null) { // Order of preference: charSet supplied, this.encoding or this.defaultEncoding in that order return Util.bytesToChar(bytes, charSet == null ? (this.encoding == null ? this.defaultEncoding : this.encoding) : charSet); } } catch (IOException e) { // ignore } return null; }
/** * @see javax.tools.FileObject#getCharContent(boolean) */ @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(this.f), this.charset.name()); }
public static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding) throws IOException { Charset charset = null; try { charset = Charset.forName(encoding); } catch (IllegalCharsetNameException e) { System.err.println("Illegal charset name : " + encoding); //$NON-NLS-1$ return null; } catch(UnsupportedCharsetException e) { System.err.println("Unsupported charset : " + encoding); //$NON-NLS-1$ return null; } CharsetDecoder charsetDecoder = charset.newDecoder(); charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE); byte[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(stream, length); ByteBuffer byteBuffer = ByteBuffer.allocate(contents.length); byteBuffer.put(contents); byteBuffer.flip(); return charsetDecoder.decode(byteBuffer).array(); }
public File getJavaHome() { if (!this.javaHomeChecked) { this.javaHomeChecked = true; this.javaHomeCache = Util.getJavaHome(); } return this.javaHomeCache; }
/** * Returns the given bytes as a char array using a given encoding (null means platform default). */ public static char[] bytesToChar(byte[] bytes, String encoding) throws IOException { return getInputStreamAsCharArray(new ByteArrayInputStream(bytes), bytes.length, encoding); }
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { if (getKind() == Kind.SOURCE) { try (ZipFile zipFile2 = new ZipFile(this.file)) { ZipEntry zipEntry = zipFile2.getEntry(this.entryName); return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(zipEntry, zipFile2), this.charset.name()); } } return null; }
private static FileOutputStream getFileOutputStream(boolean generatePackagesStructure, String outputPath, String relativeFileName) throws IOException { if (generatePackagesStructure) { return new FileOutputStream(new File(buildAllDirectoriesInto(outputPath, relativeFileName))); } else { String fileName = null; char fileSeparatorChar = File.separatorChar; String fileSeparator = File.separator; // First we ensure that the outputPath exists outputPath = outputPath.replace('/', fileSeparatorChar); // To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar); if (indexOfPackageSeparator == -1) { if (outputPath.endsWith(fileSeparator)) { fileName = outputPath + relativeFileName; } else { fileName = outputPath + fileSeparator + relativeFileName; } } else { int length = relativeFileName.length(); if (outputPath.endsWith(fileSeparator)) { fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length); } else { fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length); } } return new FileOutputStream(new File(fileName)); } }
/** * @see javax.tools.FileObject#getCharContent(boolean) */ @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(this.f), this.charset.toString()); }
public static char[] getInputStreamAsCharArray(InputStream stream, int length, String encoding) throws IOException { Charset charset = null; try { charset = Charset.forName(encoding); } catch (IllegalCharsetNameException e) { System.err.println("Illegal charset name : " + encoding); //$NON-NLS-1$ return null; } catch(UnsupportedCharsetException e) { System.err.println("Unsupported charset : " + encoding); //$NON-NLS-1$ return null; } CharsetDecoder charsetDecoder = charset.newDecoder(); charsetDecoder.onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE); byte[] contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(stream, length); ByteBuffer byteBuffer = ByteBuffer.allocate(contents.length); byteBuffer.put(contents); byteBuffer.flip(); return charsetDecoder.decode(byteBuffer).array(); }
public File getJavaHome() { if (!this.javaHomeChecked) { this.javaHomeChecked = true; this.javaHomeCache = Util.getJavaHome(); } return this.javaHomeCache; }
/** * Returns the given bytes as a char array using a given encoding (null means platform default). */ public static char[] bytesToChar(byte[] bytes, String encoding) throws IOException { return getInputStreamAsCharArray(new ByteArrayInputStream(bytes), bytes.length, encoding); }
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { if (getKind() == Kind.SOURCE) { try (ZipFile zipFile2 = new ZipFile(this.file)) { ZipEntry zipEntry = zipFile2.getEntry(this.entryName); return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(zipEntry, zipFile2), this.charset.name()); } } return null; }
private static FileOutputStream getFileOutputStream(boolean generatePackagesStructure, String outputPath, String relativeFileName) throws IOException { if (generatePackagesStructure) { return new FileOutputStream(new File(buildAllDirectoriesInto(outputPath, relativeFileName))); } else { String fileName = null; char fileSeparatorChar = File.separatorChar; String fileSeparator = File.separator; // First we ensure that the outputPath exists outputPath = outputPath.replace('/', fileSeparatorChar); // To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar); if (indexOfPackageSeparator == -1) { if (outputPath.endsWith(fileSeparator)) { fileName = outputPath + relativeFileName; } else { fileName = outputPath + fileSeparator + relativeFileName; } } else { int length = relativeFileName.length(); if (outputPath.endsWith(fileSeparator)) { fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length); } else { fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length); } } return new FileOutputStream(new File(fileName)); } }
public char[] getContents() { if (this.contents != null) return this.contents; // answer the cached source // otherwise retrieve it try { return Util.getFileCharContent(new File(new String(this.fileName)), this.encoding); } catch (IOException e) { // could not read file: returns an empty array } return CharOperation.NO_CHAR; } /**
/** * @see javax.tools.FileObject#getCharContent(boolean) */ @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(this.f), this.charset.name()); }
/** * Search the line number corresponding to a specific position * @param position int * @return int */ public final int getLineNumber(int position) { return Util.getLineNumber(position, this.lineEnds, 0, this.linePtr); } public final void setSource(char[] sourceString){
public static ClassFileReader read(InputStream stream, String fileName, boolean fullyInitialize) throws ClassFormatException, IOException { byte classFileBytes[] = Util.getInputStreamAsByteArray(stream, -1); ClassFileReader classFileReader = new ClassFileReader(classFileBytes, fileName.toCharArray()); if (fullyInitialize) { classFileReader.initialize(); } return classFileReader; }
public File getJavaHome() { if (!this.javaHomeChecked) { this.javaHomeChecked = true; this.javaHomeCache = Util.getJavaHome(); } return this.javaHomeCache; }