Skip to content

Commit d606477

Browse files
author
Stu Arnett
committed
v1.0.1
1 parent 729cc35 commit d606477

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ description = 'Smart REST Client - JAX-RS (Jersey) REST client that provides cli
2929
ext.githubProjectName = 'smart-client-java'
3030

3131
buildscript {
32-
ext.commonBuildVersion = '1.2'
32+
ext.commonBuildVersion = '1.3.1'
3333
ext.commonBuildDir = "https://raw.githubusercontent.com/emcvipr/ecs-common-build/v$commonBuildVersion"
3434
apply from: "$commonBuildDir/ecs-publish.buildscript.gradle", to: buildscript
3535
}

src/main/java/com/emc/rest/smart/SizeOverrideWriter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,13 @@ public InputStream() {
103103
super(delegate);
104104
}
105105
}
106+
107+
@Produces({"application/octet-stream", "*/*"})
108+
public static class SizedInputStream extends SizeOverrideWriter<com.emc.rest.util.SizedInputStream> {
109+
private static final SizedInputStreamWriter delegate = new SizedInputStreamWriter();
110+
111+
public SizedInputStream() {
112+
super(delegate);
113+
}
114+
}
106115
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2015, EMC Corporation.
3+
* Redistribution and use in source and binary forms, with or without modification,
4+
* are permitted provided that the following conditions are met:
5+
*
6+
* + Redistributions of source code must retain the above copyright notice,
7+
* this list of conditions and the following disclaimer.
8+
* + Redistributions in binary form must reproduce the above copyright
9+
* notice, this list of conditions and the following disclaimer in the
10+
* documentation and/or other materials provided with the distribution.
11+
* + The name of EMC Corporation may not be used to endorse or promote
12+
* products derived from this software without specific prior written
13+
* permission.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
19+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25+
* POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
package com.emc.rest.smart;
28+
29+
import com.emc.rest.util.SizedInputStream;
30+
import com.sun.jersey.core.util.ReaderWriter;
31+
32+
import javax.ws.rs.Produces;
33+
import javax.ws.rs.WebApplicationException;
34+
import javax.ws.rs.core.MediaType;
35+
import javax.ws.rs.core.MultivaluedMap;
36+
import javax.ws.rs.ext.MessageBodyWriter;
37+
import java.io.IOException;
38+
import java.io.OutputStream;
39+
import java.lang.annotation.Annotation;
40+
import java.lang.reflect.Type;
41+
42+
@Produces({"application/octet-stream", "*/*"})
43+
public class SizedInputStreamWriter implements MessageBodyWriter<SizedInputStream> {
44+
@Override
45+
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
46+
return SizedInputStream.class.isAssignableFrom(type);
47+
}
48+
49+
@Override
50+
public long getSize(SizedInputStream sizedInputStream, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
51+
return sizedInputStream.getSize();
52+
}
53+
54+
@Override
55+
public void writeTo(SizedInputStream sizedInputStream, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
56+
ReaderWriter.writeTo(sizedInputStream, entityStream);
57+
}
58+
}

src/main/java/com/emc/rest/smart/SmartClientFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public static Client createStandardClient(SmartConfig smartConfig,
8686
clientConfig.getClasses().remove(InputStreamProvider.class);
8787
clientConfig.getClasses().add(SizeOverrideWriter.ByteArray.class);
8888
clientConfig.getClasses().add(SizeOverrideWriter.File.class);
89+
clientConfig.getClasses().add(SizeOverrideWriter.SizedInputStream.class);
8990
clientConfig.getClasses().add(SizeOverrideWriter.InputStream.class);
9091
clientConfig.getClasses().add(ByteArrayProvider.class);
9192
clientConfig.getClasses().add(FileProvider.class);

0 commit comments

Comments
 (0)