-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ListBlobsResponse.java
164 lines (137 loc) · 5.69 KB
/
ListBlobsResponse.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure.services.blob.client;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.ArrayList;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import com.microsoft.windowsazure.services.core.storage.Constants;
import com.microsoft.windowsazure.services.core.storage.StorageException;
import com.microsoft.windowsazure.services.core.storage.utils.Utility;
/**
* RESERVED FOR INTERNAL USE. A class used to parse a list blobs response stream.
*/
final class ListBlobsResponse {
/**
* Holds the ArrayList of CloudBlobs from the response.
*/
private ArrayList<ListBlobItem> blobs = new ArrayList<ListBlobItem>();
/**
* Stores the value indicating if the response has been fully parsed.
*/
private boolean isParsed;
/**
* Stores the marker.
*/
private String marker;
/**
* Stores the max results.
*/
private int maxResults;
/**
* Stores the next marker.
*/
private String nextMarker;
/**
* Stores the container prefix.
*/
private String prefix;
/**
* Stores the InputStream to read from.
*/
private final InputStream streamRef;
/**
* Stores the blob delimiter.
*/
private String delimiter;
public ListBlobsResponse(final InputStream stream) {
this.streamRef = stream;
}
public ArrayList<ListBlobItem> getBlobs(final CloudBlobClient serviceClient, final CloudBlobContainer container)
throws XMLStreamException, StorageException {
if (!this.isParsed) {
this.parseResponse(serviceClient, container);
}
return this.blobs;
}
public String getDelimiter() {
return this.delimiter;
}
public String getMarker() {
return this.marker;
}
public int getMaxResults() {
return this.maxResults;
}
public String getNextMarker() {
return this.nextMarker;
}
public String getPrefix() {
return this.prefix;
}
public void parseResponse(final CloudBlobClient serviceClient, final CloudBlobContainer container)
throws XMLStreamException, StorageException {
final XMLStreamReader xmlr = Utility.createXMLStreamReaderFromStream(this.streamRef);
String tempParseString = null;
// Start document
int eventType = xmlr.getEventType();
xmlr.require(XMLStreamConstants.START_DOCUMENT, null, null);
// 1. get enumerationResults Header
eventType = xmlr.next();
xmlr.require(XMLStreamConstants.START_ELEMENT, null, "EnumerationResults");
// check if there are more events in the input stream
while (xmlr.hasNext()) {
eventType = xmlr.next();
if (eventType == XMLStreamConstants.START_ELEMENT || eventType == XMLStreamConstants.END_ELEMENT) {
final String name = xmlr.getName().toString();
if (eventType == XMLStreamConstants.START_ELEMENT && name.equals(Constants.MAX_RESULTS_ELEMENT)) {
tempParseString = Utility.readElementFromXMLReader(xmlr, Constants.MAX_RESULTS_ELEMENT);
this.maxResults = Integer.parseInt(tempParseString);
}
else if (eventType == XMLStreamConstants.START_ELEMENT && name.equals(Constants.MARKER_ELEMENT)) {
this.marker = Utility.readElementFromXMLReader(xmlr, Constants.MARKER_ELEMENT);
}
else if (eventType == XMLStreamConstants.START_ELEMENT && name.equals(Constants.NEXT_MARKER_ELEMENT)) {
this.nextMarker = Utility.readElementFromXMLReader(xmlr, Constants.NEXT_MARKER_ELEMENT);
}
else if (eventType == XMLStreamConstants.START_ELEMENT && name.equals(Constants.PREFIX_ELEMENT)) {
this.prefix = Utility.readElementFromXMLReader(xmlr, Constants.PREFIX_ELEMENT);
}
else if (eventType == XMLStreamConstants.START_ELEMENT && name.equals(Constants.DELIMITER_ELEMENT)) {
this.delimiter = Utility.readElementFromXMLReader(xmlr, Constants.DELIMITER_ELEMENT);
}
else if (eventType == XMLStreamConstants.START_ELEMENT && name.equals(BlobConstants.BLOBS_ELEMENT)) {
try {
this.blobs = BlobDeserializationHelper.readBlobItems(xmlr, serviceClient, container);
}
catch (final URISyntaxException e) {
throw new XMLStreamException(e);
}
catch (final ParseException e) {
throw new XMLStreamException(e);
}
xmlr.require(XMLStreamConstants.END_ELEMENT, null, BlobConstants.BLOBS_ELEMENT);
}
else if (eventType == XMLStreamConstants.END_ELEMENT && "EnumerationResults".equals(name)) {
break;
}
}
}
this.isParsed = true;
}
}