⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bufferiorequest.java

📁 Java写的文本编辑器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					}					// Otherwise, we found a \n					// that follows some other					// character, hence we have					// a Unix file					else					{						CROnly = false;						CRLF = false;						sbuf.append(buf,lastLine,							i - lastLine);						sbuf.append('\n');						if(trackProgress && lineCount++ % PROGRESS_INTERVAL == 0)							setProgressValue(sbuf.length());						lastLine = i + 1;					}					break;				default:					// If we find some other					// character that follows					// a \r, so it is not a					// Windows file, and probably					// a Mac file					if(lastWasCR)					{						CROnly = true;						CRLF = false;						lastWasCR = false;					}					break;				}			}			if(trackProgress)				setProgressValue(sbuf.length());			// Add remaining stuff from buffer			sbuf.append(buf,lastLine,len - lastLine);		}		setAbortable(false);		String returnValue;		if(CRLF)			returnValue = "\r\n";		else if(CROnly)			returnValue = "\r";		else			returnValue = "\n";		in.close();		// Chop trailing newline and/or ^Z (if any)		int bufferLength = sbuf.length();		if(bufferLength != 0)		{			char ch = sbuf.charAt(bufferLength - 1);			if(length >= 2 && ch == 0x1a /* DOS ^Z */				&& sbuf.charAt(bufferLength - 2) == '\n')				sbuf.setLength(bufferLength - 2);			else if(ch == '\n')				sbuf.setLength(bufferLength - 1);		}		// to avoid having to deal with read/write locks and such,		// we insert the loaded data into the buffer in the		// post-load cleanup runnable, which runs in the AWT thread.		buffer.putProperty(LOAD_DATA,sbuf);		return returnValue;	}	private void readMarkers(Buffer buffer, InputStream _in)		throws IOException	{		// For `reload' command		buffer.removeAllMarkers();		BufferedReader in = new BufferedReader(new InputStreamReader(_in));		String line;		while((line = in.readLine()) != null)		{			// compatibility kludge for jEdit 3.1 and earlier			if(!line.startsWith("!"))				continue;			char shortcut = line.charAt(1);			int start = line.indexOf(';');			int end = line.indexOf(';',start + 1);			int position = Integer.parseInt(line.substring(start + 1,end));			buffer.addMarker(shortcut,position);		}		in.close();	}	private void save()	{		OutputStream out = null;		try		{			String[] args = { vfs.getFileName(path) };			setStatus(jEdit.getProperty("vfs.status.save",args));			// the entire save operation can be aborted...			setAbortable(true);			try			{				buffer.readLock();				/* if the VFS supports renaming files, we first				 * save to #<filename>#save#, then rename that				 * to <filename>, so that if the save fails,				 * data will not be lost */				String savePath;				if((vfs.getCapabilities() & VFS.RENAME_CAP) != 0)				{					savePath = vfs.getParentOfPath(path)						+ '#' + vfs.getFileName(path)						+ "#save#";				}				else					savePath = path;				out = vfs._createOutputStream(session,savePath,view);				if(out != null)				{					if(path.endsWith(".gz"))						out = new GZIPOutputStream(out);					write(buffer,out);				}				// Only backup once per session				if(buffer.getProperty(Buffer.BACKED_UP) == null)				{					vfs._backup(session,path,view);					buffer.putProperty(Buffer.BACKED_UP,Boolean.TRUE);				}				if((vfs.getCapabilities() & VFS.RENAME_CAP) != 0)					vfs._rename(session,savePath,path,view);				// We only save markers to VFS's that support deletion.				// Otherwise, we will accumilate stale marks files.				if((vfs.getCapabilities() & VFS.DELETE_CAP) != 0)				{					if(jEdit.getBooleanProperty("persistentMarkers")						&& buffer.getMarkers().size() != 0)					{						setStatus(jEdit.getProperty("vfs.status.save-markers",args));						setProgressValue(0);						out = vfs._createOutputStream(session,markersPath,view);						if(out != null)							writeMarkers(buffer,out);					}					else						vfs._delete(session,markersPath,view);				}			}			catch(BadLocationException bl)			{				Log.log(Log.ERROR,this,bl);			}			catch(IOException io)			{				Log.log(Log.ERROR,this,io);				String[] pp = { path, io.toString() };				VFSManager.error(view,"write-error",pp);			}			finally			{				buffer.readUnlock();			}		}		catch(WorkThread.Abort a)		{			if(out != null)			{				try				{					out.close();				}				catch(IOException io)				{				}			}		}		finally		{			try			{				vfs._saveComplete(session,buffer,view);				vfs._endVFSSession(session,view);			}			catch(IOException io)			{				Log.log(Log.ERROR,this,io);				String[] pp = { path, io.toString() };				VFSManager.error(view,"write-error",pp);			}			catch(WorkThread.Abort a)			{			}		}	}	private void autosave()	{		OutputStream out = null;		try		{			String[] args = { vfs.getFileName(path) };			setStatus(jEdit.getProperty("vfs.status.autosave",args));			// the entire save operation can be aborted...			setAbortable(true);			try			{				buffer.readLock();				if(!buffer.isDirty())				{					// buffer has been saved while we					// were waiting.					return;				}				out = vfs._createOutputStream(session,path,view);				if(out == null)					return;				write(buffer,out);			}			catch(BadLocationException bl)			{				Log.log(Log.ERROR,this,bl);			}			catch(IOException io)			{				/* Log.log(Log.ERROR,this,io);				args[0] = io.toString();				VFSManager.error(view,"ioerror",args); */			}			finally			{				buffer.readUnlock();			}		}		catch(WorkThread.Abort a)		{			if(out != null)			{				try				{					out.close();				}				catch(IOException io)				{				}			}		}	}	private void write(Buffer buffer, OutputStream _out)		throws IOException, BadLocationException	{		BufferedWriter out = new BufferedWriter(			new OutputStreamWriter(_out,				(String)buffer.getProperty(Buffer.ENCODING)),				IOBUFSIZE);		Segment lineSegment = new Segment();		String newline = (String)buffer.getProperty(Buffer.LINESEP);		if(newline == null)			newline = System.getProperty("line.separator");		Element map = buffer.getDefaultRootElement();		setProgressMaximum(map.getElementCount() / PROGRESS_INTERVAL);		setProgressValue(0);		int i = 0;		while(i < map.getElementCount())		{			Element line = map.getElement(i);			int start = line.getStartOffset();			buffer.getText(start,line.getEndOffset() - start - 1,				lineSegment);			out.write(lineSegment.array,lineSegment.offset,				lineSegment.count);			out.write(newline);			if(++i % PROGRESS_INTERVAL == 0)				setProgressValue(i / PROGRESS_INTERVAL);		}		out.close();	}	private void writeMarkers(Buffer buffer, OutputStream out)		throws IOException	{		Writer o = new BufferedWriter(new OutputStreamWriter(out));		Vector markers = buffer.getMarkers();		for(int i = 0; i < markers.size(); i++)		{			Marker marker = (Marker)markers.elementAt(i);			o.write('!');			o.write(marker.getShortcut());			o.write(';');			String pos = String.valueOf(marker.getPosition());			o.write(pos);			o.write(';');			o.write(pos);			o.write('\n');		}		o.close();	}	private void insert()	{		InputStream in = null;		try		{			try			{				String[] args = { vfs.getFileName(path) };				setStatus(jEdit.getProperty("vfs.status.load",args));				setAbortable(true);				VFS.DirectoryEntry entry = vfs._getDirectoryEntry(					session,path,view);				long length;				if(entry != null)					length = entry.length;				else					length = 0L;				in = vfs._createInputStream(session,path,false,view);				if(in == null)					return;				if(path.endsWith(".gz"))					in = new GZIPInputStream(in);				read(buffer,in,length);			}			catch(IOException io)			{				Log.log(Log.ERROR,this,io);				String[] pp = { path, io.toString() };				VFSManager.error(view,"read-error",pp);			}		}		catch(WorkThread.Abort a)		{			if(in != null)			{				try				{					in.close();				}				catch(IOException io)				{				}			}		}		finally		{			try			{				vfs._endVFSSession(session,view);			}			catch(IOException io)			{				Log.log(Log.ERROR,this,io);				String[] pp = { path, io.toString() };				VFSManager.error(view,"read-error",pp);			}			catch(WorkThread.Abort a)			{			}		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -