本文整理汇总了Java中org.netbeans.api.queries.FileEncodingQuery.getEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java FileEncodingQuery.getEncoding方法的具体用法?Java FileEncodingQuery.getEncoding怎么用?Java FileEncodingQuery.getEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.queries.FileEncodingQuery
的用法示例。
在下文中一共展示了FileEncodingQuery.getEncoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MergeResultWriterInfo
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
public MergeResultWriterInfo(File tempf1, File tempf2, File tempf3,
File outputFile, String mimeType,
String leftFileRevision, String rightFileRevision,
FileObject fo, FileLock lock, Charset encoding,
String newLineString) {
this.tempf1 = tempf1;
this.tempf2 = tempf2;
this.tempf3 = tempf3;
this.outputFile = outputFile;
this.mimeType = mimeType;
this.leftFileRevision = leftFileRevision;
this.rightFileRevision = rightFileRevision;
this.fo = fo;
this.lock = lock;
this.newLineString = newLineString;
if (encoding == null) {
encoding = FileEncodingQuery.getEncoding(FileUtil.toFileObject(tempf1));
}
this.encoding = encoding;
}
示例2: saveFromKitToStream
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
@Override
protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream)
throws IOException, BadLocationException {
if (guardedProvider != null) {
Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
Writer writer = guardedProvider.createGuardedWriter(stream, c);
try {
kit.write(writer, doc, 0, doc.getLength());
} finally {
writer.close();
}
} else {
super.saveFromKitToStream(doc, kit, stream);
}
}
示例3: associateEncoding
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
/**
* Retrieves the Charset for the referenceFile and associates it weakly with
* the given file. A following getAssociatedEncoding() call for
* the file will then return the referenceFile-s Charset.
*
* @param referenceFile the file which charset has to be used when encoding file
* @param file file to be encoded with the referenceFile-s charset
*
*/
public static void associateEncoding(File referenceFile, File file) {
FileObject refFO = FileUtil.toFileObject(referenceFile);
if (refFO == null || refFO.isFolder()) {
return;
}
FileObject fo = FileUtil.toFileObject(file);
if (fo == null || fo.isFolder()) {
return;
}
Charset c = FileEncodingQuery.getEncoding(refFO);
if (c != null) {
synchronized(ENCODING_LOCK) {
if (fileToFileObject == null) {
fileToFileObject = new WeakHashMap<File, FileObject>();
}
fileToFileObject.put(file, fo);
}
associateEncoding(fo, c);
}
}
示例4: expandTemplate
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
public static void expandTemplate(InputStream template, FileObject toFile, Map<String, Object> values) throws IOException {
Charset targetEncoding = FileEncodingQuery.getEncoding(toFile);
if(toFile.isLocked()){
LOG.log(Level.SEVERE, "File {0} is locked", new Object[]{toFile.getName()});
return;
}
FileLock lock = toFile.lock();
try (Writer writer = new OutputStreamWriter(toFile.getOutputStream(lock), targetEncoding)) {
expandTemplate(new InputStreamReader(template), writer, values, targetEncoding);
} finally {
lock.releaseLock();
}
DataObject dob = DataObject.find(toFile);
if (dob != null) {
reformat(dob);
}
}
示例5: readFile
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
public static String readFile( FileObject file ) throws IOException {
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
FileUtil.copy(inputStream, outputStream);
Charset charset = FileEncodingQuery.getEncoding(file);
return outputStream.toString(charset.name());
}
finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException ignore) {
}
}
}
}
示例6: saveFromKitToStream
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
/** Store the document in proper encoding.
*/
protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream out) throws IOException, BadLocationException {
// not calling super.
String enc = EncodingUtil.detectEncoding(doc);
// saved form saveDocument()
Charset cs = fileEncoding.get();
// + fallback, if no info is available
if (cs == null) {
if (enc != null) {
cs = Charset.forName(enc);
} else {
// fallback to the original encoding, no encoding in document istelf.
cs = FileEncodingQuery.getEncoding(getDataObject().getPrimaryFile());
}
}
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("Saving using encoding");//, new RuntimeException (enc)); // NOI18N
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("!!! TextEditorSupport::saveFromKitToStream: enc = " + enc);
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("!!! ::saveFromKitToStream: after first test -> OK");
FilterOutputStream fos = new FilterOutputStream(out) {
@Override
public void close() throws IOException {
flush();
}
};
CharsetEncoder encoder = cs.newEncoder();
encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
Writer w = new OutputStreamWriter (fos, encoder);
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("!!! ::saveFromKitToStream: writer = " + w);
try {
kit.write(w, doc, 0, doc.getLength());
} finally {
w.close();
}
}
示例7: createApplication
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
private FileObject createApplication(String name) throws IOException {
int index = name.lastIndexOf('.');
final String pkg;
final String sn;
if (index >= 0) {
pkg = name.substring(0, index);
sn = name.substring(index+1);
} else {
pkg = null;
sn = name;
}
final FileObject file = FileUtil.createData(srcRoot, name.replace('.', '/') + ".java"); //NOI18N
final FileLock lock = file.lock();
try (final PrintWriter out = new PrintWriter(new OutputStreamWriter(
file.getOutputStream(lock),
FileEncodingQuery.getEncoding(file)))) {
out.println(
pkg == null ? "" :"package " + pkg +";\n" + //NOI18N
"import javafx.application.Application;\n" + //NOI18N
"import javafx.stage.Stage;\n" + //NOI18N
"public class " + sn + " extends Application {\n" + //NOI18N
" public void start(Stage primaryStage) {}\n"+ //NOI18N
"}" //NOI18N
);
} finally {
lock.releaseLock();
}
return file;
}
示例8: createReader
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
@Override
public Reader createReader() throws IOException {
if (type != null) {
return new InputStreamReader(fileObject.getInputStream(), FileEncodingQuery.getEncoding(type));
} else {
return new InputStreamReader(fileObject.getInputStream(), FileEncodingQuery.getEncoding(fileObject));
}
}
示例9: getEncoding
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
private Charset getEncoding(File file) {
try {
return FileEncodingQuery.getEncoding(FileUtil.toFileObject(file));
} catch (Throwable e) { // TODO: workaround for #108850
// return default
}
return Charset.defaultCharset();
}
示例10: getEncoding
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
@CheckForNull
Charset getEncoding() {
if (!encodingInitialized) {
encoding = rootNotNeeded ? null : FileEncodingQuery.getEncoding(ctx.getRoot());
encodingInitialized = true;
}
return encoding;
}
示例11: encoding
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
private Charset encoding() {
Charset e = encoding;
if (e == null) {
FileObject file = FileUtil.toFileObject(root);
if (file != null) {
e = FileEncodingQuery.getEncoding(file);
} else {
// avoid further checks
e = UNKNOWN_CHARSET;
}
encoding = e;
}
return e != UNKNOWN_CHARSET ? e : null;
}
示例12: saveFromKitToStream
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
@Override
protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, BadLocationException {
if (guardedProvider != null) {
Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
Writer writer = guardedProvider.createGuardedWriter(stream, c);
try {
kit.write(writer, doc, 0, doc.getLength());
} finally {
writer.close();
}
} else {
super.saveFromKitToStream(doc, kit, stream);
}
}
示例13: ensureProjectAttrs
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
private static void ensureProjectAttrs(Map<String, Object> map, FileObject parent) {
if (map.get(ATTR_LICENSE) == null) {
map.put(ATTR_LICENSE, "default"); // NOI18N
}
if (map.get(ATTR_LICENSE_PATH) == null) {
map.put(ATTR_LICENSE_PATH, "Templates/Licenses/license-" + map.get(ATTR_LICENSE).toString() + ".txt"); // NOI18N
}
String url = map.get(ATTR_LICENSE_PATH).toString();
if (FileUtil.getConfigFile(url) == null) { //now we have filesystem based template for sure, convert to file:///path to have freemarker process it
try {
URI uri = URI.create(url);
//freemarker.cache.TemplateCache.normalizeName appears to
// check for :// to skip processing the path
map.put(ATTR_LICENSE_PATH, new URI("file", "", uri.getPath(), null).toString());
} catch (Exception malformedURLException) {
}
} else {
// now we have to assume we are dealing with the teplate from system filesystem.
// in order to get through the freemarker, the path needs to "absolute" in freemarker terms - http://freemarker.sourceforge.net/docs/ref_directive_include.html
// relative would mean relative to the template and we cannot be sure what the path from template to license template is..
// it used to be, ../Licenses/ or ../../Licenses but can be anything similar, just based on where the template resides.
map.put(ATTR_LICENSE_PATH, "/" + url);
//appears to cover both the new and old default value of the include path
}
if (map.get(ATTR_ENCODING) == null) {
Charset charset = FileEncodingQuery.getEncoding(parent);
String encoding = charset != null ? charset.name() : "UTF-8"; // NOI18N
map.put(ATTR_ENCODING, encoding);
}
}
示例14: read
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
private void read(final FileObject data) throws IOException {
final Charset cs = FileEncodingQuery.getEncoding(data);
final BufferedReader in = new BufferedReader(new InputStreamReader(data.getInputStream(), cs));
try {
CharBuffer buffer = CharBuffer.allocate(1024);
while (in.read(buffer)>0) {
buffer.clear();
}
} finally {
in.close();
}
}
示例15: checkMeasuredInternal
import org.netbeans.api.queries.FileEncodingQuery; //导入方法依赖的package包/类
@Override
protected Def checkMeasuredInternal(FileObject fo,
SearchListener listener) {
MappedByteBuffer bb = null;
FileChannel fc = null;
try {
listener.fileContentMatchingStarted(fo.getPath());
File file = FileUtil.toFile(fo);
// Open the file and then get a channel from the stream
FileInputStream fis = new FileInputStream(file);
fc = fis.getChannel();
// Get the file's size and then map it into memory
int sz = (int) fc.size();
bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
// if (asciiPattern && !matchesIgnoringEncoding(bb)) {
// return null;
//}
// Decode the file into a char buffer
Charset charset = FileEncodingQuery.getEncoding(fo);
CharsetDecoder decoder = prepareDecoder(charset);
decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
CharBuffer cb = decoder.decode(bb);
List<TextDetail> textDetails = matchWholeFile(cb, fo);
if (textDetails == null) {
return null;
} else {
Def def = new Def(fo, decoder.charset(), textDetails);
return def;
}
} catch (Exception e) {
listener.generalError(e);
return null;
} finally {
if (fc != null) {
try {
fc.close();
} catch (IOException ex) {
listener.generalError(ex);
}
}
MatcherUtils.unmap(bb);
}
}