📄 file.java
字号:
package org.ehotsoft.yekki.upload;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
public class File
{
protected Upload parent;
protected int startData;
protected int endData;
protected int size;
protected String fieldName;
protected String fileName;
protected String fileExt;
protected String filePathName;
protected String contentType;
protected String contentDisp;
protected String typeMime;
protected String subTypeMime;
protected String contentString;
protected boolean isMissing;
public static final int SAVEAS_AUTO = 0;
public static final int SAVEAS_VIRTUAL = 1;
public static final int SAVEAS_PHYSICAL = 2;
File( ){
startData = 0;
endData = 0;
size = 0;
fieldName = new String( );
fileName = new String( );
fileExt = new String( );
filePathName = new String( );
contentType = new String( );
contentDisp = new String( );
typeMime = new String( );
subTypeMime = new String( );
contentString = new String( );
isMissing = true;
}
public void saveAs( String destFilePathName )
throws UploadException, IOException {
saveAs( destFilePathName, 0 );
}
public void saveAs( String destFilePathName, int optionSaveAs )
throws UploadException, IOException {
String path = new String( );
path = parent.getPhysicalPath( destFilePathName, optionSaveAs );
if( path == null )
throw new IllegalArgumentException( "There is no specified destination file ( 1140 )." );
try {
java.io.File file = new java.io.File( path );
FileOutputStream fileOut = new FileOutputStream( file );
fileOut.write( parent.binArray, startData, size );
fileOut.close( );
}
catch( IOException e ) {
throw new UploadException( "File can't be saved ( 1120 )." );
}
}
public boolean isMissing( ) {
return isMissing;
}
public String getFieldName( ){
return fieldName;
}
public String getFileName( ) {
return fileName;
}
public String getFilePathName( ){
return this.filePathName;
}
public String getFileExt( ){
return this.fileExt;
}
public String getContentType( ){
return this.contentType;
}
public String getContentDisp( ){
return this.contentDisp;
}
public String getContentString( ){
String strTMP = new String( parent.binArray, startData, size );
return strTMP;
}
public String getTypeMIME( )
throws IOException {
return typeMime;
}
public String getSubTypeMIME( ) {
return this.subTypeMime;
}
public int getSize( ) {
return size;
}
public int getStartData( ) {
return startData;
}
protected int getEndData( )
{
return this.endData;
}
protected void setParent( Upload parent ) {
this.parent = parent;
}
protected void setStartData( int startData ) {
this.startData = startData;
}
protected void setEndData( int endData ) {
endData = endData;
}
protected void setSize( int size ) {
this.size = size;
}
protected void setIsMissing( boolean isMissing ) {
this.isMissing = isMissing;
}
protected void setFieldName( String fieldName ) {
this.fieldName = fieldName;
}
protected void setFileName( String fileName ) {
this.fileName = fileName;
}
protected void setFilePathName( String filePathName ) {
this.filePathName = filePathName;
}
protected void setFileExt( String fileExt ) {
this.fileExt = fileExt;
}
protected void setContentType( String contentType ) {
this.contentType = contentType;
}
protected void setContentDisp( String contentDisp ) {
this.contentDisp = contentDisp;
}
protected void setTypeMIME( String TypeMime ) {
this.typeMime = TypeMime;
}
protected void setSubTypeMIME( String subTypeMime ) {
this.subTypeMime = subTypeMime;
}
public byte[] getBinaryData() {
return parent.binArray;
}
public byte getBinaryData( int index ) {
if( startData + index > endData )
throw new ArrayIndexOutOfBoundsException( "Index Out of range ( 1115 )." );
if( startData + index <= endData )
return parent.binArray[ startData + index ];
else
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -