buffer.insertString(0,sbuf.toString(),null);   Element map = buffer.getDefaultRootElement(); for(int i = 0; i < Math.min(10,map.getElementCount()); i++) { Element line = map.getElement(i); String text = buffer.getText(line.getStartOffset(), line.getEndOffset() - line.getStartOffset() - 1); processProperty(buffer,text); }
buffer.putProperty(LOAD_DATA,sbuf);
	public void read(Buffer buffer, InputStream _in)		throws IOException, BadLocationException	{		boolean trackProgress; // only true if the file size is known		int bufLength;		File file = buffer.getFile();		if(file != null)		{			bufLength = (int)file.length();			setProgressMaximum(bufLength);			trackProgress = true;		}		else		{			bufLength = IOBUFSIZE * 4;			trackProgress = false;		}		setProgressValue(0);		StringBuffer sbuf = new StringBuffer(bufLength);		InputStreamReader in = new InputStreamReader(_in,			jEdit.getProperty("buffer.encoding",			System.getProperty("file.encoding")));		char[] buf = new char[IOBUFSIZE];		// Number of characters in 'buf' array.		// InputStream.read() doesn't always fill the		// array (eg, the file size is not a multiple of		// IOBUFSIZE, or it is a GZipped file, etc)		int len;		// True if a \n was read after a \r. Usually		// means this is a DOS/Windows file		boolean CRLF = false;		// A \r was read, hence a MacOS file		boolean CROnly = false;		// Was the previous read character a \r?		// If we read a \n and this is true, we assume		// we have a DOS/Windows file		boolean lastWasCR = false;				while((len = in.read(buf,0,buf.length)) != -1)		{			// Offset of previous line, relative to			// the start of the I/O buffer (NOT			// relative to the start of the document)			int lastLine = 0;			for(int i = 0; i < len; i++)			{				// Look for line endings.				switch(buf[i])				{				case '\r':					// If we read a \r and					// lastWasCR is also true,					// it is probably a Mac file					// (\r\r in stream)					if(lastWasCR)					{						CROnly = true;						CRLF = false;					}					// Otherwise set a flag,					// so that \n knows that last					// was a \r					else					{						lastWasCR = true;					}					// Insert a line					sbuf.append(buf,lastLine,i -						lastLine);					sbuf.append('\n');					// This is i+1 to take the					// trailing \n into account					lastLine = i + 1;					break;				case '\n':					// If lastWasCR is true,					// we just read a \r followed					// by a \n. We specify that					// this is a Windows file,					// but take no further					// action and just ignore					// the \r.					if(lastWasCR)					{						CROnly = false;						CRLF = true;						lastWasCR = false;						// Bump lastLine so						// that the next line						// doesn't erronously						// pick up the \r						lastLine = i + 1;					}					// 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');						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;				}			}			// Add remaining stuff from buffer			sbuf.append(buf,lastLine,len - lastLine);			setProgressValue(sbuf.length());		}		// Can't abort the rest, otherwise the buffer may be		// left in an inconsistent state		setAbortable(false);		if(CRLF)			buffer.putProperty(Buffer.LINESEP,"\r\n");		else if(CROnly)			buffer.putProperty(Buffer.LINESEP,"\r");		else			buffer.putProperty(Buffer.LINESEP,"\n");		in.close();		// For `reload' command		buffer.remove(0,buffer.getLength());		// Chop trailing newline and/or ^Z (if any)		int length = sbuf.length();		if(length != 0)		{			char ch = sbuf.charAt(length - 1);			if(length >= 2 && ch == 0x1a /* DOS ^Z */				&& sbuf.charAt(length - 2) == '\n')				sbuf.setLength(length - 2);			else if(ch == '\n')				sbuf.setLength(length - 1);		}		buffer.insertString(0,sbuf.toString(),null);		// Process buffer-local properties		Element map = buffer.getDefaultRootElement();		for(int i = 0; i < Math.min(10,map.getElementCount()); i++)		{			Element line = map.getElement(i);			String text = buffer.getText(line.getStartOffset(),				line.getEndOffset() - line.getStartOffset() - 1);			processProperty(buffer,text);		}		buffer.setNewFile(false);	}