OWL ITS + 탐지시스템(인터넷 진흥원)
jhjang
2021-10-14 d680ff9fa4298ad3c0cd12f5f9d87f6c51110480
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
package kr.wisestone.owl.web.converter;
 
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.FileCopyUtils;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
public class FileHttpMessageConverter implements HttpMessageConverter<File> {
 
    private List<MediaType> supportMediaTypes = new ArrayList<MediaType>();
 
    public FileHttpMessageConverter() {
        this.supportMediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
    }
 
    @Override
    public boolean canRead(Class<?> arg0, MediaType mediaType) {
        // TODO Auto-generated method stub
        return false;
    }
 
    @Override
    public boolean canWrite(Class<?> clazz, MediaType mediaType) {
        // TODO Auto-generated method stub
        return File.class.equals(clazz);
    }
 
    @Override
    public List<MediaType> getSupportedMediaTypes() {
        // TODO Auto-generated method stub
        return supportMediaTypes;
    }
 
    @Override
    public void write(File file, MediaType mediaType, HttpOutputMessage message)
            throws IOException, HttpMessageNotWritableException {
        if(mediaType == null){
            mediaType = MediaType.APPLICATION_OCTET_STREAM;
        }
 
        message.getHeaders().setContentType(mediaType);
 
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
            FileCopyUtils.copy(fis, message.getBody());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                fis.close();
            }
        }
 
    }
 
    @Override
    public File read(Class<? extends File> arg0, HttpInputMessage arg1)
            throws IOException, HttpMessageNotReadableException {
        // TODO Auto-generated method stub
        return null;
    }
 
 
}