de16b137b0eceada40176fded72efd4848faf14c
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.oc_framework
.operations
;
20 import java
.io
.Serializable
;
22 import android
.os
.Parcel
;
23 import android
.os
.Parcelable
;
25 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavEntry
;
26 import com
.owncloud
.android
.oc_framework
.utils
.FileUtils
;
29 * Contains the data of a Remote File from a WebDavEntry
34 public class RemoteFile
implements Parcelable
, Serializable
{
36 /** Generated - should be refreshed every time the class changes!! */
37 private static final long serialVersionUID
= 532139091191390616L;
39 private String mRemotePath
;
40 private String mMimeType
;
42 private long mCreationTimestamp
;
43 private long mModifiedTimestamp
;
50 public String
getRemotePath() {
54 public void setRemotePath(String remotePath
) {
55 this.mRemotePath
= remotePath
;
58 public String
getMimeType() {
62 public void setMimeType(String mimeType
) {
63 this.mMimeType
= mimeType
;
66 public long getLength() {
70 public void setLength(long length
) {
71 this.mLength
= length
;
74 public long getCreationTimestamp() {
75 return mCreationTimestamp
;
78 public void setCreationTimestamp(long creationTimestamp
) {
79 this.mCreationTimestamp
= creationTimestamp
;
82 public long getModifiedTimestamp() {
83 return mModifiedTimestamp
;
86 public void setModifiedTimestamp(long modifiedTimestamp
) {
87 this.mModifiedTimestamp
= modifiedTimestamp
;
90 public String
getEtag() {
94 public void setEtag(String etag
) {
99 * Create new {@link RemoteFile} with given path.
101 * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
103 * @param path The remote path of the file.
105 public RemoteFile(String path
) {
107 if (path
== null
|| path
.length() <= 0 || !path
.startsWith(FileUtils
.PATH_SEPARATOR
)) {
108 throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path
);
113 public RemoteFile(WebdavEntry we
) {
114 this(we
.decodedPath());
115 this.setCreationTimestamp(we
.createTimestamp());
116 this.setLength(we
.contentLength());
117 this.setMimeType(we
.contentType());
118 this.setModifiedTimestamp(we
.modifiedTimestamp());
119 this.setEtag(we
.etag());
123 * Used internally. Reset all file properties
125 private void resetData() {
129 mCreationTimestamp
= 0;
130 mModifiedTimestamp
= 0;
137 public static final Parcelable
.Creator
<RemoteFile
> CREATOR
= new Parcelable
.Creator
<RemoteFile
>() {
139 public RemoteFile
createFromParcel(Parcel source
) {
140 return new RemoteFile(source
);
144 public RemoteFile
[] newArray(int size
) {
145 return new RemoteFile
[size
];
151 * Reconstruct from parcel
153 * @param source The source parcel
155 protected RemoteFile(Parcel source
) {
156 readFromParcel(source
);
159 public void readFromParcel (Parcel source
) {
160 mRemotePath
= source
.readString();
161 mMimeType
= source
.readString();
162 mLength
= source
.readLong();
163 mCreationTimestamp
= source
.readLong();
164 mModifiedTimestamp
= source
.readLong();
165 mEtag
= source
.readString();
169 public int describeContents() {
170 return this.hashCode();
174 public void writeToParcel(Parcel dest
, int flags
) {
175 dest
.writeString(mRemotePath
);
176 dest
.writeString(mMimeType
);
177 dest
.writeLong(mLength
);
178 dest
.writeLong(mCreationTimestamp
);
179 dest
.writeLong(mModifiedTimestamp
);
180 dest
.writeString(mEtag
);