-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.java
More file actions
71 lines (58 loc) · 1.73 KB
/
Input.java
File metadata and controls
71 lines (58 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package javaxt.html;
//******************************************************************************
//** HTML Input
//******************************************************************************
/**
* Used to represent a single html form input.
*
******************************************************************************/
public class Input {
private String name;
private Object value;
public Input(String name, String value){
this.name = name;
this.value = value;
}
public Input(String name, javaxt.io.File file){
this.name = name;
this.value = file;
}
public String getName(){
return name;
}
public Object getValue(){
return value;
}
public String toString(){
return name + "=" + (value==null ? "" :
(this.isFile() ? ((javaxt.io.File) value).getName() : value ));
}
public byte[] toByteArray(){
if (value!=null){
if (this.isFile()){
return ((javaxt.io.File) value).getBytes().toByteArray();
}
else{
try{
return value.toString().getBytes("UTF-8");
}
catch(java.io.UnsupportedEncodingException e){}
}
}
return null;
}
/** Returns the size of the value. */
public long getSize(){
if (value==null) return 0;
else{
if (this.isFile()) return ((javaxt.io.File) value).getSize();
else return this.toByteArray().length;
}
}
public boolean isFile(){
if (value!=null){
return (value instanceof javaxt.io.File);
}
return false;
}
}