commit | author | age
|
70d888
|
1 |
/* |
U |
2 |
http-image - Image extensions to jdk.httpserver |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.httpserver.image; |
|
19 |
|
|
20 |
import java.io.File; |
|
21 |
import java.io.IOException; |
|
22 |
import java.util.ArrayList; |
|
23 |
import java.util.Iterator; |
|
24 |
import java.util.List; |
|
25 |
import java.util.logging.Level; |
|
26 |
import java.util.logging.Logger; |
|
27 |
|
|
28 |
/** |
|
29 |
* Eine Klasse zur Erzeugung verkleinerter sowie Base64-enkodierter Fassungen |
|
30 |
* einer Bilddatei innerhalb eines Threads. |
|
31 |
* |
|
32 |
* @author Ulrich Hilger |
|
33 |
* @version 1, 14.06.2021 |
|
34 |
*/ |
|
35 |
public class ImageThread extends Thread { |
|
36 |
|
|
37 |
private List<ThreadListener> listeners; |
|
38 |
private File dir; |
|
39 |
private File toFile; |
|
40 |
private String relName; |
|
41 |
private String indicator; |
|
42 |
private int size; |
|
43 |
private Datei datei; |
|
44 |
private String ext; |
|
45 |
|
|
46 |
public ImageThread(File dir, String relName, String indicator, int size, File toFile, Datei datei, String ext) { |
|
47 |
super(); |
|
48 |
listeners = new ArrayList(); |
|
49 |
this.dir = dir; |
|
50 |
this.relName = relName; |
|
51 |
this.indicator = indicator; |
|
52 |
this.size = size; |
|
53 |
this.toFile = toFile; |
|
54 |
this.datei = datei; |
|
55 |
this.ext = ext; |
|
56 |
} |
|
57 |
|
|
58 |
protected void sendFinished() { |
|
59 |
Iterator<ThreadListener> i = listeners.iterator(); |
|
60 |
while (i.hasNext()) { |
|
61 |
ThreadListener listener = i.next(); |
|
62 |
listener.finished(); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
protected void clear() { |
|
67 |
sendFinished(); |
|
68 |
listeners.clear(); |
|
69 |
listeners = null; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* starten mit |
|
74 |
* |
|
75 |
* <pre> |
|
76 |
* Thread p = new ImageThread(..); |
|
77 |
* p.start(); |
|
78 |
* </pre> |
|
79 |
*/ |
|
80 |
@Override |
|
81 |
public void run() { |
|
82 |
try { |
|
83 |
ImageActor be = new ImageActor(); |
|
84 |
be.createImage(dir, relName, indicator, size, toFile); |
|
85 |
be.setImgSrc(datei, ext, toFile); |
|
86 |
clear(); |
|
87 |
} catch (IOException ex) { |
|
88 |
Logger.getLogger(ImageThread.class.getName()).log(Level.SEVERE, null, ex); |
|
89 |
clear(); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
public void addListener(ThreadListener listener) { |
|
94 |
listeners.add(listener); |
|
95 |
} |
|
96 |
|
|
97 |
public void removeListener(ThreadListener listener) { |
|
98 |
listeners.remove(listener); |
|
99 |
} |
|
100 |
|
|
101 |
public interface ThreadListener { |
|
102 |
|
|
103 |
public void finished(); |
|
104 |
} |
|
105 |
|
|
106 |
} |