本文整理了Java中org.eclipse.jdt.internal.compiler.util.Util
类的一些代码示例,展示了Util
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util
类的具体详情如下:
包路径:org.eclipse.jdt.internal.compiler.util.Util
类名称:Util
暂无
代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core
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;
}
/**
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
/**
* 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
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
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;
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
/**
* @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());
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
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();
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
public File getJavaHome() {
if (!this.javaHomeChecked) {
this.javaHomeChecked = true;
this.javaHomeCache = Util.getJavaHome();
}
return this.javaHomeCache;
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
/**
* 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);
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
@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;
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
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));
}
}
代码示例来源:origin: com.ovea.tajin.server/tajin-server-tomcat7
/**
* @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());
}
代码示例来源:origin: org.eclipse.jetty.orbit/org.eclipse.jdt.core
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();
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
public File getJavaHome() {
if (!this.javaHomeChecked) {
this.javaHomeChecked = true;
this.javaHomeCache = Util.getJavaHome();
}
return this.javaHomeCache;
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
/**
* 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);
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
@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;
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
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));
}
}
代码示例来源:origin: trylimits/Eclipse-Postfix-Code-Completion
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;
}
/**
代码示例来源:origin: org.eclipse.jetty.orbit/org.eclipse.jdt.core
/**
* @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());
}
代码示例来源:origin: org.eclipse.jdt.core.compiler/ecj
/**
* 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){
代码示例来源:origin: org.eclipse.scout.sdk.deps/ecj
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;
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core
public File getJavaHome() {
if (!this.javaHomeChecked) {
this.javaHomeChecked = true;
this.javaHomeCache = Util.getJavaHome();
}
return this.javaHomeCache;
}
内容来源于网络,如有侵权,请联系作者删除!