-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPicture.java
More file actions
106 lines (91 loc) · 2.05 KB
/
Picture.java
File metadata and controls
106 lines (91 loc) · 2.05 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package beans;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.sql.Date;
public class Picture implements Serializable{
//写真ID
private int id=0;
//名前
private String name=null;
//コンテキストタイプ
private String contextType=null;
//画像データのバイト配列
byte[]photo=null;
//入力日
private Date date=null;
//引数なしのコンストラクタ
public Picture() {}
//引数ありのコンストラクタ
public Picture(int id, String name, String contextType, byte[] photo, Date date) {
super();
this.id = id;
this.name = name;
this.contextType = contextType;
this.photo = photo;
this.date = date;
}
//getter,setterメソッド
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContextType() {
return contextType;
}
public void setContextType(String contextType) {
this.contextType = contextType;
}
public byte[] getPhoto() {
return photo;
}
public void setPhoto(byte[] photo) {
this.photo = photo;
}
public void setBlob(InputStream is) {
// 画像データの読み込み
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len;
try {
while((len=is.read(buf))>0) {
baos.write(buf,0,len);
}
//バッファを取得
this.photo=baos.toByteArray();
}catch(IOException e) {
e.printStackTrace();
}finally {
if(is!=null) {
try {
is.close();
}catch(IOException e) {
e.printStackTrace();
}
}
if(baos!=null) {
try {
baos.close();
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}