org.gjt.sp.jedit.bufferio.BufferLoadRequest Maven / Gradle / Ivy
Go to download
This project aims to build a command line tool that can create
HTML view with syntax highlighted source code.
It uses Jedit syntax highlighting engine and support all languages that are supported in JEdit.
Which are currently: ActionScript, Ada 95, ANTLR, Apache HTTPD, APDL, AppleScript, ASP, Aspect-J, Assembly, AWK, B formal method, Batch, BBj, BCEL, BibTeX, C, C++, C#, CHILL, CIL, COBOL, ColdFusion, CSS, CVS Commit, D, DOxygen, DSSSL, Eiffel, EmbPerl, Erlang, Factor, Fortran, Foxpro, FreeMarker, Fortran, Gettext, Groovy, Haskell, HTML, Icon, IDL, Inform, INI, Inno Setup, Informix 4GL, Interlis, Io, Java, JavaScript, JCL, JHTML, JMK, JSP, Latex, Lilypond, Lisp, LOTOS, Lua, Makefile, Maple, ML, Modula-3, MoinMoin, MQSC, NetRexx, NQC, NSIS2, Objective C, ObjectRexx, Occam, Omnimark, Parrot, Pascal, Patch, Perl, PHP, Pike, PL-SQL, PL/I, Pop11, PostScript, Povray, PowerDynamo, Progress 4GL, Prolog, Properties, PSP, PV-WAVE, Pyrex, Python, REBOL, Redcode, Relax-NG, RelationalView, Rest, Rib, RPM spec, RTF, Ruby, Ruby-HTML, RView, S+, S#, SAS, Scheme, SDL/PL, SGML, Shell Script, SHTML, Smalltalk, SMI MIB, SQR, Squidconf, SVN Commit, Swig, TCL, TeX, Texinfo, TPL, Transact-SQL, UnrealScript, VBScript, Velocity, Verilog, VHDL, XML, XSL, ZPT
The newest version!
/*
* BufferLoadRequest.java - I/O request
* :tabSize=8:indentSize=8:noTabs=false:
* :folding=explicit:collapseFolds=1:
*
* Copyright (C) 2000, 2005 Slava Pestov
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.gjt.sp.jedit.bufferio;
//{{{ Imports
import java.io.*;
import java.nio.charset.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.zip.GZIPInputStream;
import org.gjt.sp.jedit.io.*;
import org.gjt.sp.jedit.*;
import org.gjt.sp.jedit.buffer.JEditBuffer;
import org.gjt.sp.util.*;
//}}}
/**
* A buffer load request.
* @author Slava Pestov
* @version $Id: BufferLoadRequest.java 12504 2008-04-22 23:12:43Z ezust $
*/
public class BufferLoadRequest extends BufferIORequest
{
//{{{ BufferLoadRequest constructor
/**
* Creates a new buffer I/O request.
* @param view The view
* @param buffer The buffer
* @param session The VFS session
* @param vfs The VFS
* @param path The path
*/
public BufferLoadRequest(View view, Buffer buffer,
Object session, VFS vfs, String path)
{
super(view,buffer,session,vfs,path);
} //}}}
//{{{ run() method
public void run()
{
try
{
setAbortable(true);
if(!buffer.isTemporary())
{
String[] args = { vfs.getFileName(path) };
setStatus(jEdit.getProperty("vfs.status.load",args));
setValue(0L);
}
path = vfs._canonPath(session,path,view);
readContents();
buffer.setNewFile(false);
if (jEdit.getBooleanProperty("persistentMarkers") &&
(vfs.isMarkersFileSupported()))
{
InputStream markers = null;
try
{
String[] args = { vfs.getFileName(path) };
if(!buffer.isTemporary())
setStatus(jEdit.getProperty("vfs.status.load-markers",args));
setAbortable(true);
markers = vfs._createInputStream(session,markersPath,true,view);
if(markers != null)
readMarkers(buffer,markers);
}
catch(Exception e)
{
// ignore
}
finally
{
IOUtilities.closeQuietly(markers);
}
}
}
catch(Exception e)
{
Log.log(Log.ERROR,this,e);
Object[] pp = { e.toString() };
VFSManager.error(view,path,"ioerror.read-error",pp);
buffer.setBooleanProperty(ERROR_OCCURRED,true);
}
catch(OutOfMemoryError oom)
{
Log.log(Log.ERROR,this,oom);
VFSManager.error(view,path,"out-of-memory-error",null);
buffer.setBooleanProperty(ERROR_OCCURRED,true);
}
catch(WorkThread.Abort a)
{
buffer.setBooleanProperty(ERROR_OCCURRED,true);
}
finally
{
try
{
vfs._endVFSSession(session,view);
}
catch(Exception e)
{
Log.log(Log.ERROR,this,e);
String[] pp = { e.toString() };
VFSManager.error(view,path,"ioerror.read-error",pp);
buffer.setBooleanProperty(ERROR_OCCURRED,true);
}
catch(WorkThread.Abort a)
{
buffer.setBooleanProperty(ERROR_OCCURRED,true);
}
}
} //}}}
//{{{ getNakedStream() method
/**
* Returns the raw contents stream for this load request.
* This stream is not buffered or unzipped.
*/
private InputStream getNakedStream() throws IOException
{
InputStream in = vfs._createInputStream(session,path,false,view);
if(in != null)
{
return in;
}
throw new IOException("Unable to get a Stream for " + path);
} //}}}
//{{{ getContentLength() method
/**
* Returns content length of this load request.
*/
private long getContentLength() throws IOException
{
VFSFile entry = vfs._getFile(session,path,view);
if(entry != null)
return entry.getLength();
else
return 0L;
} //}}}
//{{{ rewindContentsStream() method
/**
* Returns rewinded contents stream.
* This method assumes the marked stream was made by
* getMarkedStream() method. The stream may be reopened if reset()
* failed.
*/
private BufferedInputStream rewindContentsStream(BufferedInputStream markedStream, boolean gzipped)
throws IOException
{
try
{
markedStream.reset();
return markedStream;
}
catch(IOException e)
{
Log.log(Log.NOTICE, this
, path + ": Reopening to rewind the stream");
// Reopen the stream because the mark has been
// invalidated while previous reading.
markedStream.close();
InputStream in = getNakedStream();
try
{
if(gzipped)
{
in = new GZIPInputStream(in);
}
BufferedInputStream result
= AutoDetection.getMarkedStream(in);
in = null;
return result;
}
finally
{
IOUtilities.closeQuietly(in);
}
}
} //}}}
//{{{ readContents() method
/**
* Read the contents of this load request.
* Some auto detection is performed if enabled.
* - GZIPed file
* - The encoding
* If fallback encodings are specified, they are used on
* encoding errors.
*/
private void readContents() throws IOException
{
long length = getContentLength();
BufferedInputStream markedStream
= AutoDetection.getMarkedStream(getNakedStream());
try
{
boolean gzipped = false;
// encodingProviders is consist of given
// encodings as String or contents-aware
// detectors as EncodingDetector.
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy