2015. 3. 14. 22:19
  • File 클래스는 문서(Document)의 "물리적인 상태 정보"를 나타내는 클래스입니다. 파일 위치(URL), 체크섬(cheksum), 크기(size), 파일 버전(file version) 등의 속성을 포함하고 있습니다.
  • 파일 위치를 경로(path)가 아니라, URL 클래스로 선언한 것은 PC 혹은 서버의 로컬 디스크에 존재하는 파일 뿐만 아니라 인터넷 상에 존재하는 파일 위치를 지정할 수 있도록 하기 위해서입니다. checksum 문자열은 파일의 무결성(integrity)와 중복 검사(duplication check) 목적으로 사용됩니다.
  • File 클래스 또한 FileVersion 클래스 처럼 방어적 코딩이 포함되어 있습니다.



File.java

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
package docar.archive.document;
 
import java.net.URL;
 
/**
 * "파일"은 "문서"의 구성요소이다.
 *
 * - 문서는 하나 이상의 파일을 포함할 수 있다.
 * - 각각의 파일은 문서의 다른 버전을 표현한다.
 * - 파일은 문서의 물리적인 형태를 의미한다.
 *
 * @author "Sunny Kwak"
 */
public class File {
    private URL location;
    private String checksum;
    private long size;
    private FileVersion fileVersion;
 
    /**
     * '파일' 생성자.
     *
     * @param location 파일의 위치
     * @param checksum 파일 식별을 위한 지문(finger print)
     * @param size 파일 크기.
     * @param fileVersion 파일 버전.
     * @throws IllegalArgumentException 필수 항목이 누락된 경우, 예외 처리
     */
    public File(URL location, String checksum, long size,
            FileVersion fileVersion) {
         
        if(location == null) {
            throw new IllegalArgumentException("location arguement is missing");
        }
        if(checksum == null || checksum.isEmpty()) {
            throw new IllegalArgumentException("checksum argument is missing");
        }
        if(size < 1) {
            throw new IllegalArgumentException("Invalid fie size. Input file = " + location);
        }
        if(fileVersion == null) {
            throw new IllegalArgumentException("fileVersion argument is missing");
        }
         
        this.location = location;
        this.checksum = checksum;
        this.size = size;
        this.fileVersion = fileVersion;
    }
Posted by 곽중선