-
Notifications
You must be signed in to change notification settings - Fork 24.3k
/
StoreFileMetaData.java
115 lines (93 loc) · 3.23 KB
/
StoreFileMetaData.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
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
107
108
109
110
111
112
113
114
115
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.index.store;
import org.apache.lucene.store.Directory;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import java.io.IOException;
/**
* @author kimchy (shay.banon)
*/
public class StoreFileMetaData implements Streamable {
private String name;
private long lastModified;
private long length;
private String checksum;
private transient Directory directory;
StoreFileMetaData() {
}
public StoreFileMetaData(String name, long length, long lastModified, String checksum) {
this(name, length, lastModified, checksum, null);
}
public StoreFileMetaData(String name, long length, long lastModified, String checksum, @Nullable Directory directory) {
this.name = name;
this.lastModified = lastModified;
this.length = length;
this.checksum = checksum;
this.directory = directory;
}
public Directory directory() {
return this.directory;
}
public String name() {
return name;
}
public long lastModified() {
return this.lastModified;
}
public long length() {
return length;
}
@Nullable public String checksum() {
return this.checksum;
}
public boolean isSame(StoreFileMetaData other) {
if (checksum == null || other.checksum == null) {
return false;
}
return length == other.length && checksum.equals(other.checksum);
}
public static StoreFileMetaData readStoreFileMetaData(StreamInput in) throws IOException {
StoreFileMetaData md = new StoreFileMetaData();
md.readFrom(in);
return md;
}
@Override public String toString() {
return "name [" + name + "], length [" + length + "], checksum [" + checksum + "]";
}
@Override public void readFrom(StreamInput in) throws IOException {
name = in.readUTF();
length = in.readVLong();
if (in.readBoolean()) {
checksum = in.readUTF();
}
}
@Override public void writeTo(StreamOutput out) throws IOException {
out.writeUTF(name);
out.writeVLong(length);
if (checksum == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeUTF(checksum);
}
}
}