@Override @NonNull public final Writer openWriter() throws IOException { final FileObject file = handle.resolveFileObject(true); if (file == null) { throw new IOException("Cannot create file: " + toString()); //NOI18N } return new OutputStreamWriter ( this.openOutputStream(), FileEncodingQuery.getEncoding(file)); }
@Override public void run () { try { doc.remove(0,doc.getLength()); doc.insertString(0,new String( data, 0, pos, FileEncodingQuery.getEncoding(getHandle().resolveFileObject(false))), null); } catch (BadLocationException e) { if (LOG.isLoggable(Level.SEVERE)) LOG.log(Level.SEVERE, e.getMessage(), e); } } });
private long getFileLastModified() { final FileObject file = handle.resolveFileObject(false); try { //Prefer class files to packed sources, the packed sources may have wrong time stamps. if (file == null || file.getFileSystem() instanceof JarFileSystem) { return 0L; } } catch (FileStateInvalidException e) { //Handled below } return file.lastModified().getTime(); }
@Override public final boolean delete() { if (isDirty() != null) { //If the file is modified in editor do not delete it return false; } else { final FileObject file = handle.resolveFileObject(false); if (file == null) { return false; } try { FileLock lock = file.lock(); try { file.delete (lock); return true; } finally { lock.releaseLock(); } } catch (IOException e) { return false; } } }
@Override public FileObject resolveFileObject(boolean write) { FileObject res = super.resolveFileObject(write); if (res == null) { try { if (write) { //Create the file file = FileUtil.createData(root,getRelativePath()); } else { //Resolve file file = URLMapper.findFileObject(path); } res = file; } catch (IOException e) { //pass, return null } } return res; }
@Override @NonNull protected final CharSequence createContent() throws IOException { final FileObject file = getHandle().resolveFileObject(false); if (file == null) { throw new FileNotFoundException("Cannot open file: " + toString()); } final Source source = Source.create(file); if (source == null) { throw new IOException("No source for: " + FileUtil.getFileDisplayName(file)); //NOI18N } CharSequence content = source.createSnapshot().getText(); if (hasFilter && source.getDocument(false) == null) { content = filter(content); } return content; }
public final void update (CharSequence content) throws IOException { if (content == null) { update(); } else { if (filter != null) { final FileObject file = handle.resolveFileObject(false); if (file != null) { final Source source = Source.create(file); if (source != null && source.getDocument(false) == null) { content = filter.filterCharSequence(content); } } } this.text = toString(content); } this.tokens = null; }
@Override protected final Long isDirty() { final FileObject file = getHandle().resolveFileObject(false); if (file == null) { return null; } final Source source = Source.create(file); if (source != null) { Document doc = source.getDocument(false); if (doc != null) { return DocumentUtilities.getDocumentTimestamp(doc); } } return null; }
@Override @NonNull public final OutputStream openOutputStream() throws IOException { final FileObject file = handle.resolveFileObject(true); if (file == null) { throw new IOException("Cannot create file: " + toString()); //NOI18N } OutputStream res = createOutputStream(); if (res == null) { res = new LckStream (file); } return res; }
@Override @CheckForNull protected final OutputStream createOutputStream() throws IOException { final FileObject file = getHandle().resolveFileObject(true); if (file == null) { throw new IOException("Cannot create file: " + toString()); //NOI18N } final StyledDocument doc = getDocument(); if (doc != null) { return new DocumentStream (doc); } return null; }
@Override public StyledDocument getDocument() { final FileObject file = getHandle().resolveFileObject(false); if (file == null) { return null; } final Source src = Source.create(file); if (src == null) { return null; } final Document doc = src.getDocument(false); return (doc instanceof StyledDocument) ? ((StyledDocument)doc) : null; }
private boolean isModifiedByWorkingCopy() { final FileObject file = handle.resolveFileObject(false); if (file == null) { return false; } return SourceFileManager.getModifiedFiles().isModified(file.toURI()); }