There are 24 code examples for java.io.FileInputStream.
The API names are highlighted below.
You can use
button
to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.
Project Name: TowerOfZaldagor Package: filehandler
Source Code: Filehandler.java (Click to view .java file)
Method Code:
public static boolean load(){
FileDialog f=new FileDialog(new Frame(),"Load game",FileDialog.LOAD);
f.setVisible(true);
String filename=f.getDirectory() + f.getFile();
if (f.getFile() != null) {
try {
FileInputStream fis=new FileInputStream(filename);
try {
ObjectInputStream ois=new ObjectInputStream(fis);
try {
Engine.engine.setPlayer((Player)ois.readObject());
ois.close();
fis.close();
}
catch ( ClassNotFoundException e) {
e.printStackTrace();
}
}
catch ( IOException e) {
e.printStackTrace();
}
}
catch ( FileNotFoundException e) {
e.printStackTrace();
}
return true;
}
return false;
}
Project Name: codecover Package: org.codecover.eclipse.utils.recommendationgenerator
Source Code: LineNumberDeterminator.java (Click to view .java file)
Method Code:
public static List<Integer> getLineNumbers(IResource resource,int offsetStart,int offsetEnd){
long a=new Date().getTime();
List<Integer> ret=new ArrayList<Integer>();
List<Integer> lineBreakPositions;
if (lineBreakPositionMap.containsKey(resource)) {
lineBreakPositions=lineBreakPositionMap.get(resource);
}
else {
lineBreakPositions=new ArrayList<Integer>();
IFile iFile=wsRoot.getFile(resource.getFullPath());
String portableString=iFile.getLocation().toPortableString();
File file=new File(portableString);
FileInputStream fis;
try {
fis=new FileInputStream(file);
int n=0;
int count=0;
while ((n=fis.read()) != -1) {
count++;
if (n == 10) {
lineBreakPositions.add(count);
}
}
fis.close();
}
catch ( FileNotFoundException e) {
e.printStackTrace();
}
catch ( IOException e) {
e.printStackTrace();
}
lineBreakPositionMap.put(resource,lineBreakPositions);
}
int beginline=1;
int endline=1;
for ( Integer lineBreakPosition : lineBreakPositions) {
if (lineBreakPosition < offsetStart) {
beginline++;
}
if (lineBreakPosition < offsetEnd) {
endline++;
}
}
for (int i=beginline; i <= endline; i++) {
ret.add(i);
}
return ret;
}
Project Name: codecover-model Package: org.codecover.model.utils.file
Source Code: FileTool.java (Click to view .java file)
Method Code:
/**
* Copies a file <code>source</code> to the file <code>target</code> by
* honoring charsets.<br>
* <br>
* If the <code>target</code> exists, it is overwritten, else it is created.
* All parent folders of <code>target</code> are created before.
* @param source The source file to copy.
* @param sourceCharset The charset of the source file.
* @param target The destination, where to copy source.
* @param targetCharset The charset of the target file.
* @throws IOException If there occur read / write exceptions.
*/
public static void copy(File source,Charset sourceCharset,File target,Charset targetCharset) throws IOException {
File absoluteSource=source.getAbsoluteFile();
File absoluteTarget=target.getAbsoluteFile();
absoluteTarget.getParentFile().mkdirs();
FileInputStream fileInputStream=new FileInputStream(absoluteSource);
InputStreamReader reader=new InputStreamReader(fileInputStream,sourceCharset);
FileOutputStream fileOutputStream=new FileOutputStream(absoluteTarget);
OutputStreamWriter writer=new OutputStreamWriter(fileOutputStream,targetCharset);
try {
char[] buffer=new char[COPY_BUFFER_SIZE];
while (true) {
int iReadSize=reader.read(buffer);
if (iReadSize > 0) {
writer.write(buffer,0,iReadSize);
}
else {
break;
}
}
writer.flush();
}
finally {
reader.close();
writer.close();
}
}
Project Name: icTAKES Package: edu.mayo.bmi.nlp.parser.ae.util
Source Code: XMIReader.java (Click to view .java file)
Method Code:
@Override public void getNext(JCas jCas) throws IOException, CollectionException {
FileInputStream inputStream=new FileInputStream(this.filesIter.next());
try {
XmiCasDeserializer.deserialize(new BufferedInputStream(inputStream),jCas.getCas());
}
catch ( SAXException e) {
throw new CollectionException(e);
}
inputStream.close();
this.completed+=1;
}
Project Name: icTAKES Package: edu.mayo.bmi.uima.pos_tagger
Source Code: POSTagger.java (Click to view .java file)
Method Code:
public void initialize(UimaContext uimaContext) throws ResourceInitializationException {
super.initialize(uimaContext);
String posModelPath=null;
try {
posModelPath=(String)uimaContext.getConfigParameterValue(POS_MODEL_FILE_PARAM);
File posModelFile=FileLocator.locateFile(posModelPath);
String modelFileAbsPath=posModelFile.getAbsolutePath();
logger.info("POS tagger model file: " + modelFileAbsPath);
boolean caseSensitive=(Boolean)uimaContext.getConfigParameterValue(CASE_SENSITIVE_PARAM);
String tagDictionaryPath=(String)uimaContext.getConfigParameterValue(TAG_DICTIONARY_PARAM);
TagDictionary tagDictionary=null;
if (tagDictionaryPath != null && !tagDictionaryPath.trim().equals("")) {
File tagDictFile=FileLocator.locateFile(tagDictionaryPath);
String tagDictFileAbsPath=tagDictFile.getAbsolutePath();
logger.info("POS tagger tag-dictionary: " + tagDictFileAbsPath);
tagDictionary=new POSDictionary(tagDictFileAbsPath,caseSensitive);
}
else {
logger.info("No POS tagger tag-dictionary.");
}
FileInputStream fis=new FileInputStream(posModelFile);
POSModel modelFile=new POSModel(fis);
tagger=new opennlp.tools.postag.POSTaggerME(modelFile);
}
catch ( Exception e) {
logger.info("POS tagger model: " + posModelPath);
throw new ResourceInitializationException(e);
}
}
Project Name: icTAKES Package: org.chboston.cnlp.ctakes.parser.uima.ae
Source Code: ParserEvaluationAnnotator.java (Click to view .java file)
Method Code:
@Override public void initialize(org.apache.uima.UimaContext aContext) throws org.apache.uima.resource.ResourceInitializationException {
String modelFileOrDirname=(String)aContext.getConfigParameterValue("modelDir");
try {
FileInputStream fis=new FileInputStream(new File(modelFileOrDirname));
ParserModel model=new ParserModel(fis);
parser=ParserFactory.create(model,AbstractBottomUpParser.defaultBeamSize,AbstractBottomUpParser.defaultAdvancePercentage);
}
catch ( IOException e) {
e.printStackTrace();
}
}
Project Name: icTAKES Package: org.mitre.medfacts.uima.assertion
Source Code: ConvertXMIAssertionsToi2b2Format.java (Click to view .java file)
Method Code:
public static void main(String[] args) throws IOException, InvalidXMLException, CASException {
File dir=new File(args[0]);
File odir=new File(args[2]);
String desc=args[1];
FileInputStream inputStream=null;
int assertionType=Assertion.type;
CAS cas=null;
try {
cas=getTypeSystemFromDescriptor(desc);
}
catch ( Exception e) {
throw new RuntimeException(e);
}
if (cas != null) {
for ( File file : dir.listFiles()) {
try {
inputStream=new FileInputStream(file);
PrintWriter writer=new PrintWriter(new java.io.File(odir + "/" + file.getName()));
XmiCasDeserializer.deserialize(inputStream,cas);
JCas jcas=cas.getJCas();
String sofaString=jcas.getDocumentText();
System.err.println("Converting text string: " + sofaString);
CharacterOffsetToLineTokenConverterDefaultImpl converter=new CharacterOffsetToLineTokenConverterDefaultImpl(sofaString);
AnnotationIndex<Annotation> aIndex=jcas.getAnnotationIndex(assertionType);
for ( Annotation a : aIndex) {
Assertion ai=(Assertion)a;
int begin=ai.getBegin();
int end=ai.getEnd();
LineAndTokenPosition begPos=converter.convert(begin);
LineAndTokenPosition endPos=converter.convert(end);
writer.println("c=\"" + sofaString.substring(begin,end) + "\" "+ begPos.getLine()+ ":"+ begPos.getTokenOffset()+ " "+ endPos.getLine()+ ":"+ endPos.getTokenOffset()+ "||t=\"problem\"||a=\""+ ai.getAssertionType()+ "\"");
}
writer.close();
}
catch ( Exception e) {
throw new RuntimeException(e);
}
finally {
if (inputStream != null) inputStream.close();
}
}
}
}
Project Name: jbidwatcher Package: com.cyberfox.util.config
Source Code: JConfig.java (Click to view .java file)
Method Code:
public static Properties loadArbitrary(String cfgName){
File checkExistence=new File(cfgName);
if (checkExistence.exists()) {
try {
FileInputStream fis=new FileInputStream(cfgName);
return (loadArbitrary(fis));
}
catch ( IOException e) {
JConfig.log().handleException("Failed to load configuration " + cfgName,e);
}
}
return (null);
}
Project Name: jbidwatcher Package: com.jbidwatcher.util
Source Code: GZip.java (Click to view .java file)
Method Code:
/**
* Load a GZipped file into memory.
* @noinspection ResultOfMethodCallIgnored
* @param fp - The file to load from.
* @throws IOException - If there are any errors reading from the file.
*/
public void load(File fp) throws IOException {
FileInputStream fis=new FileInputStream(fp);
fis.read(_gzTest);
if (_gzTest[0] == 0x1f && _gzTest[1] == -117) {
if (fis.skip(8) == 8) {
_data=new byte[(int)fp.length() - 18 + 16];
fis.read(_data,0,(int)fp.length() - 18);
_uccrc32=readInt(fis);
_uclength=readInt(fis);
nowrap=true;
}
}
else {
_data=new byte[(int)fp.length()];
System.arraycopy(_gzTest,0,_data,0,2);
nowrap=false;
fis.read(_data,2,_data.length - 2);
}
fis.close();
}
Project Name: jbidwatcher Package: com.jbidwatcher.util
Source Code: StringTools.java (Click to view .java file)
Method Code:
public static void cat(File fp,byte[][] buf){
try {
buf[0]=new byte[(int)fp.length()];
FileInputStream fis=new FileInputStream(fp);
int read=fis.read(buf[0],0,(int)fp.length());
if (read != fp.length()) JConfig.log().logDebug("Couldn't read any data from " + fp.getName());
fis.close();
}
catch ( IOException e) {
JConfig.log().handleException("Can't read file " + fp.getName(),e);
}
}
Project Name: jnode-core Package: org.jnode.vm.isolate
Source Code: VmStreamBindings.java (Click to view .java file)
Method Code:
/**
* Create an isolated stdin.
* @return
* @throws IOException
*/
final InputStream createIsolatedIn() throws IOException {
final InputStream stream;
if (inStream != null) {
stream=new WrappedInputStream(inStream);
}
else if (inSocket != null) {
stream=new WrappedInputStream(inSocket.getInputStream());
}
else {
IOContext ioContext=VmIsolate.getRoot().getIOContext();
stream=new WrappedInputStream(ioContext.getRealSystemIn());
}
return stream;
}
Project Name: megamek Package: megamek.client.bot
Source Code: BotClient.java (Click to view .java file)
Method Code:
public String getRandomBotMessage(){
String message="";
try {
String scrapFile="./mmconf/botmessages.txt";
FileInputStream fis=new FileInputStream(scrapFile);
BufferedReader dis=new BufferedReader(new InputStreamReader(fis));
while (dis.ready()) {
message=dis.readLine();
if (Compute.randomInt(10) == 1) {
break;
}
}
}
catch ( FileNotFoundException fnfe) {
return null;
}
catch ( Exception ex) {
System.err.println("Error while reading ./mmconf/botmessages.txt.");
ex.printStackTrace();
return null;
}
return message;
}
Project Name: megamek Package: megamek.server
Source Code: ScenarioLoader.java (Click to view .java file)
Method Code:
private Properties loadProperties() throws Exception {
Properties props=new Properties();
FileInputStream fis=new FileInputStream(m_scenFile);
props.load(fis);
fis.close();
int loop;
String key;
StringBuffer value;
Properties fixed=new Properties();
Enumeration<Object> keyIt=props.keys();
while (keyIt.hasMoreElements()) {
key=keyIt.nextElement().toString();
value=new StringBuffer(props.getProperty(key));
for (loop=value.length() - 1; loop >= 0; loop--) {
if (!Character.isWhitespace(value.charAt(loop))) {
break;
}
}
value.setLength(loop + 1);
fixed.setProperty(key,value.toString());
}
return fixed;
}
Project Name: randoop Package: randoop.experiments
Source Code: RandoopRun.java (Click to view .java file)
Method Code:
private void run(RunType runType,String resultsFile,MultiRunResults results,boolean reproduceISSTA06) throws IOException {
System.out.println("========== RUNNING EXPERIMENT:");
System.out.println(toString());
int numTries=0;
boolean success=false;
while (!success) {
clean(runType);
try {
callRandoop(runType);
}
catch ( Command.KillBecauseTimeLimitExceed e) {
System.out.println("Run of randoop terminated because it appears to be nonterminating.");
numTries++;
continue;
}
verifyResults(runType);
printResultsToStdout(resultsFile);
Properties p=new Properties();
FileInputStream inputStream=null;
try {
inputStream=new FileInputStream(resultsFile);
p.load(inputStream);
}
finally {
if (inputStream != null) inputStream.close();
}
String experimentName=(runType == RunType.ONLINE ? "online" : "offline") + this.base.experimentName.replace(".","");
results.addRunResults(experimentName,p);
if (reproduceISSTA06) {
try {
numTries++;
ReproduceISSTA06.checkIfReproduced(runType,this.base.experimentName,p);
success=true;
}
catch ( ReproduceISSTA06Failure e) {
System.out.println("Failed to reproduce experiment (try: " + numTries + " out of "+ MAX_TRIES_TO_REPRODUCE_ISSTA06+ ", message: "+ e.getMessage());
if (numTries == MAX_TRIES_TO_REPRODUCE_ISSTA06) {
throw new RuntimeException("Failed to reproduce " + MAX_TRIES_TO_REPRODUCE_ISSTA06 + " times. This is the"+ " lmit of tries.");
}
}
}
else {
success=true;
}
}
}
Project Name: randoop Package: randoop.main
Source Code: GenTests.java (Click to view .java file)
Method Code:
/**
* Read a list of sequences from a serialized file
*/
public static List<ExecutableSequence> read_sequences(String filename){
List<ExecutableSequence> seqs=null;
try {
FileInputStream fileis=new FileInputStream(filename);
ObjectInputStream objectis=new ObjectInputStream(new GZIPInputStream(fileis));
@SuppressWarnings("unchecked") List<ExecutableSequence> seqs_tmp=(List<ExecutableSequence>)objectis.readObject();
seqs=seqs_tmp;
objectis.close();
fileis.close();
}
catch ( Exception e) {
throw new Error(e);
}
return seqs;
}
Project Name: randoop Package: randoop.main
Source Code: CovUtils.java (Click to view .java file)
Method Code:
@SuppressWarnings("unchecked") private static Set<Branch> covset(String filename){
Map<CoverageAtom,Set<Sequence>> inputmap=new LinkedHashMap<CoverageAtom,Set<Sequence>>();
try {
FileInputStream fileis=new FileInputStream(filename);
ObjectInputStream objectis=new ObjectInputStream(new GZIPInputStream(fileis));
inputmap=(Map<CoverageAtom,Set<Sequence>>)objectis.readObject();
objectis.close();
fileis.close();
}
catch ( Exception e) {
throw new Error(e);
}
Set<Branch> covset=new LinkedHashSet<Branch>();
for ( CoverageAtom ca : inputmap.keySet()) {
covset.add((Branch)ca);
}
return covset;
}
Project Name: randoop Package: randoop.util
Source Code: SerializationHelper.java (Click to view .java file)
Method Code:
public static Object readSerialized(File inFile){
Object ret=null;
try {
FileInputStream fs=new FileInputStream(inFile);
ObjectInputStream in=null;
in=new ObjectInputStream(fs);
ret=in.readObject();
in.close();
fs.close();
return ret;
}
catch ( Exception e) {
Log.out.println("When trying to read serialized file " + inFile + ", exception thrown: "+ e);
e.printStackTrace();
throw new Error(e);
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist.service
Source Code: DBHelper.java (Click to view .java file)
Method Code:
public static void copyFileIO(File originFile,File destinationFile,IProgressMonitor monitor){
FileInputStream inputStream=null;
FileOutputStream outputStream=null;
try {
inputStream=new FileInputStream(originFile);
if (!destinationFile.exists()) destinationFile.createNewFile();
outputStream=new FileOutputStream(destinationFile);
int i=0;
byte[] buf=new byte[BUFFER];
while ((i=inputStream.read(buf)) != -1 && !monitor.isCanceled()) {
outputStream.write(buf,0,i);
monitor.worked(1);
}
}
catch ( IOException e) {
throw new PersistenceException(e);
}
finally {
closeQuietly(inputStream);
closeQuietly(outputStream);
}
}
Project Name: weka Package: weka.core.json
Source Code: Parser.java (Click to view .java file)
Method Code:
/**
* Runs the parser from commandline. Expects a filename as first parameter,
* pointing to a JSON file.
* @param args the commandline arguments
* @throws Exception if something goes wrong
*/
public static void main(String args[]) throws Exception {
if (args.length != 1) {
System.err.println("No JSON file specified!");
System.exit(1);
}
FileInputStream stream=new FileInputStream(args[0]);
SymbolFactory sf=new DefaultSymbolFactory();
Parser parser=new Parser(new Scanner(stream,sf),sf);
parser.parse();
StringBuffer buffer=new StringBuffer();
parser.getResult().toString(buffer);
System.out.println(buffer.toString());
}
Project Name: weka Package: weka.core.xml
Source Code: XMLSerialization.java (Click to view .java file)
Method Code:
/**
* for testing only. if the first argument is a filename with ".xml"
* as extension it tries to generate an instance from the XML description
* and does a <code>toString()</code> of the generated object.
*/
public static void main(String[] args) throws Exception {
if (args.length > 0) {
if (args[0].toLowerCase().endsWith(".xml")) {
System.out.println(new XMLSerialization().read(args[0]).toString());
}
else {
FileInputStream fi=new FileInputStream(args[0]);
ObjectInputStream oi=new ObjectInputStream(new BufferedInputStream(fi));
Object o=oi.readObject();
oi.close();
new XMLSerialization().write(new BufferedOutputStream(new FileOutputStream(args[0] + ".xml")),o);
FileOutputStream fo=new FileOutputStream(args[0] + ".exp");
ObjectOutputStream oo=new ObjectOutputStream(new BufferedOutputStream(fo));
oo.writeObject(o);
oo.close();
}
}
}
Project Name: weka Package: weka.core.xml
Source Code: SerialUIDChanger.java (Click to view .java file)
Method Code:
/**
* loads a serialized object and returns it
* @param binary the filename that points to the file containing the
* serialized object
* @return the object from the file
* @throws Exception if reading fails
*/
protected static Object readBinary(String binary) throws Exception {
FileInputStream fi;
ObjectInputStream oi;
Object o;
fi=new FileInputStream(binary);
oi=new ObjectInputStream(new BufferedInputStream(fi));
o=oi.readObject();
oi.close();
return o;
}
Project Name: weka Package: weka.experiment
Source Code: Experiment.java (Click to view .java file)
Method Code:
/**
* Loads an experiment from a file.
* @param filename the file to load the experiment from
* @return the experiment
* @throws Exception if loading fails
*/
public static Experiment read(String filename) throws Exception {
Experiment result;
if ((KOML.isPresent()) && (filename.toLowerCase().endsWith(KOML.FILE_EXTENSION))) {
result=(Experiment)KOML.read(filename);
}
else if (filename.toLowerCase().endsWith(".xml")) {
XMLExperiment xml=new XMLExperiment();
result=(Experiment)xml.read(filename);
}
else {
FileInputStream fi=new FileInputStream(filename);
ObjectInputStream oi=new ObjectInputStream(new BufferedInputStream(fi));
result=(Experiment)oi.readObject();
oi.close();
}
return result;
}
Project Name: weka Package: weka.experiment.xml
Source Code: XMLExperiment.java (Click to view .java file)
Method Code:
/**
* for testing only. if the first argument is a filename with ".xml"
* as extension it tries to generate an instance from the XML description
* and does a <code>toString()</code> of the generated object.
* Otherwise it loads the binary file, saves the XML representation in a
* file with the original filename appended by ".xml" and once again in a
* binary file with the original filename appended by ".exp".
* @param args the commandline arguments
* @throws Exception if something goes wrong, e.g., file not found
*/
public static void main(String[] args) throws Exception {
if (args.length > 0) {
if (args[0].toLowerCase().endsWith(".xml")) {
System.out.println(new XMLExperiment().read(args[0]).toString());
}
else {
FileInputStream fi=new FileInputStream(args[0]);
ObjectInputStream oi=new ObjectInputStream(new BufferedInputStream(fi));
Object o=oi.readObject();
oi.close();
new XMLExperiment().write(new BufferedOutputStream(new FileOutputStream(args[0] + ".xml")),o);
FileOutputStream fo=new FileOutputStream(args[0] + ".exp");
ObjectOutputStream oo=new ObjectOutputStream(new BufferedOutputStream(fo));
oo.writeObject(o);
oo.close();
}
}
}
Project Name: weka Package: weka.gui.experiment
Source Code: RunPanel.java (Click to view .java file)
Method Code:
/**
* Tests out the run panel from the command line.
* @param args may contain options specifying an experiment to run.
*/
public static void main(String[] args){
try {
boolean readExp=Utils.getFlag('l',args);
final String expFile=Utils.getOption('f',args);
if (readExp && (expFile.length() == 0)) {
throw new Exception("A filename must be given with the -f option");
}
Experiment exp=null;
if (readExp) {
FileInputStream fi=new FileInputStream(expFile);
ObjectInputStream oi=new ObjectInputStream(new BufferedInputStream(fi));
Object to=oi.readObject();
if (to instanceof RemoteExperiment) {
exp=(RemoteExperiment)to;
}
else {
exp=(Experiment)to;
}
oi.close();
}
else {
exp=new Experiment();
}
System.err.println("Initial Experiment:\n" + exp.toString());
final JFrame jf=new JFrame("Run Weka Experiment");
jf.getContentPane().setLayout(new BorderLayout());
final RunPanel sp=new RunPanel(exp);
jf.getContentPane().add(sp,BorderLayout.CENTER);
jf.addWindowListener(new WindowAdapter(){
public void windowClosing( WindowEvent e){
System.err.println("\nExperiment Configuration\n" + sp.m_Exp.toString());
jf.dispose();
System.exit(0);
}
}
);
jf.pack();
jf.setVisible(true);
}
catch ( Exception ex) {
ex.printStackTrace();
System.err.println(ex.getMessage());
}
}