Add 'sdk/java-v2/' from commit '55f103e336ca9fb8bf1720d2ef4ee8dd4e221118'
[arvados.git] / sdk / java-v2 / src / main / java / org / arvados / client / logic / collection / FileToken.java
1 /*
2  * Copyright (C) The Arvados Authors. All rights reserved.
3  *
4  * SPDX-License-Identifier: AGPL-3.0 OR Apache-2.0
5  *
6  */
7
8 package org.arvados.client.logic.collection;
9
10 import com.google.common.base.Strings;
11 import org.arvados.client.common.Characters;
12
13 public class FileToken {
14
15     private int filePosition;
16     private int fileSize;
17     private String fileName;
18     private String path;
19
20     public FileToken(String fileTokenInfo) {
21         splitFileTokenInfo(fileTokenInfo);
22     }
23
24     public FileToken(String fileTokenInfo, String path) {
25         splitFileTokenInfo(fileTokenInfo);
26         this.path = path;
27     }
28
29     private void splitFileTokenInfo(String fileTokenInfo) {
30         String[] tokenPieces = fileTokenInfo.split(":");
31         this.filePosition = Integer.parseInt(tokenPieces[0]);
32         this.fileSize = Integer.parseInt(tokenPieces[1]);
33         this.fileName = tokenPieces[2].replace(Characters.SPACE, " ");
34     }
35
36     @Override
37     public String toString() {
38         return filePosition + ":" + fileSize + ":" + fileName;
39     }
40
41     public String getFullPath() {
42         return Strings.isNullOrEmpty(path) ? fileName : path + fileName;
43     }
44
45     public int getFilePosition() {
46         return this.filePosition;
47     }
48
49     public int getFileSize() {
50         return this.fileSize;
51     }
52
53     public String getFileName() {
54         return this.fileName;
55     }
56
57     public String getPath() {
58         return this.path;
59     }
60 }