109 lines
2.7 KiB
Java
109 lines
2.7 KiB
Java
import java.net.*;
|
|
import java.io.*;
|
|
|
|
class OutFile
|
|
{
|
|
private boolean mIsOkay;
|
|
private URL mOutFile;
|
|
private URLConnection mConnection;
|
|
private DataOutputStream mOutData;
|
|
private String mStrLine;
|
|
public OutFile()
|
|
{
|
|
mIsOkay=false;
|
|
}
|
|
public OutFile(URL resBase,String strHostPathFileName)throws Exception
|
|
{
|
|
mIsOkay=false;
|
|
open(resBase,strHostPathFileName);
|
|
}
|
|
public OutFile(String strHostPathFileName)throws Exception
|
|
{
|
|
mIsOkay=false;
|
|
open(strHostPathFileName);
|
|
}
|
|
public OutFile(String resBase,String strHostPathFileName)throws Exception
|
|
{
|
|
mIsOkay=false;
|
|
open(resBase,strHostPathFileName);
|
|
}
|
|
public void open(URL resBase,String strHostPathFileName)throws Exception
|
|
{
|
|
close();
|
|
try{mOutFile=new URL(resBase,strHostPathFileName);}
|
|
catch(MalformedURLException exception){throw new Exception();}
|
|
try{mConnection=mOutFile.openConnection();}
|
|
catch(Exception exception){throw new Exception();}
|
|
mConnection.setDoOutput(true);
|
|
try{mOutData=new DataOutputStream(mConnection.getOutputStream());}
|
|
catch(Exception exception){throw new Exception();}
|
|
mIsOkay=true;
|
|
}
|
|
public void open(String resBase,String strHostPathFileName)throws Exception
|
|
{
|
|
open(resBase+strHostPathFileName);
|
|
}
|
|
public void open(String strHostPathFileName)throws Exception
|
|
{
|
|
close();
|
|
try{mOutFile=new URL(strHostPathFileName);}
|
|
catch(MalformedURLException exception){throw new Exception();}
|
|
try{mConnection=mOutFile.openConnection();}
|
|
catch(IOException ioException){throw new Exception();}
|
|
mConnection.setDoOutput(true);
|
|
try{mOutData=new DataOutputStream(mConnection.getOutputStream());}
|
|
catch(Exception exception){throw new Exception();}
|
|
mIsOkay=true;
|
|
}
|
|
public void close ()
|
|
{
|
|
if(!isOkay())return;
|
|
try{mOutData.close();}
|
|
catch(Exception exception){;}
|
|
mIsOkay=false;
|
|
}
|
|
public void flush()throws Exception
|
|
{
|
|
if(!isOkay())throw new Exception();
|
|
mOutData.flush();
|
|
}
|
|
|
|
public void write(String strLine)throws Exception
|
|
{
|
|
if(!isOkay())throw new Exception();
|
|
mOutData.writeBytes(strLine);
|
|
}
|
|
public void write(double value)throws Exception
|
|
{
|
|
if(!isOkay())throw new Exception();
|
|
mOutData.writeDouble(value);
|
|
}
|
|
public void write(int value)throws Exception
|
|
{
|
|
if(!isOkay())throw new Exception();
|
|
mOutData.writeInt(value);
|
|
}
|
|
public int size()
|
|
{
|
|
if(!isOkay())return 0;
|
|
return mOutData.size();
|
|
}
|
|
public boolean isOkay()
|
|
{
|
|
return mIsOkay;
|
|
}
|
|
};
|
|
|
|
// public String readLine()throws Exception
|
|
// {
|
|
// if(!isOkay())throw new Exception();
|
|
// try{mStrLine=new String(mInData.readLine());}
|
|
// catch(IOException ioException){throw new Exception();}
|
|
// return mStrLine;
|
|
// }
|
|
// public boolean isOkay()
|
|
// {
|
|
// return mIsOkay;
|
|
// }
|
|
//};
|