Skip to content

Package: DownloadComplete$Origin

DownloadComplete$Origin

nameinstructionbranchcomplexitylinemethod
static {...}
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.downloader;
28:
29: import javax.annotation.Nonnegative;
30: import javax.annotation.Nonnull;
31: import javax.annotation.concurrent.Immutable;
32: import java.io.IOException;
33: import java.nio.file.Files;
34: import java.nio.file.Path;
35: import java.net.URI;
36: import java.net.URL;
37: import lombok.Getter;
38: import lombok.RequiredArgsConstructor;
39: import lombok.ToString;
40:
41: /***********************************************************************************************************************
42: *
43: * @author Fabrizio Giudici
44: *
45: **********************************************************************************************************************/
46: @Immutable @RequiredArgsConstructor @Getter @ToString(exclude = "bytes")
47: public class DownloadComplete
48: {
49: public enum Origin
50: {
51: NETWORK,
52: CACHE
53: }
54:
55: @Nonnull
56: private final URL url;
57:
58: @Nonnegative
59: private final int statusCode;
60:
61: @Nonnull
62: private final byte[] bytes;
63:
64: @Nonnull
65: private final Origin origin;
66:
67: @Nonnull
68: public URI getCachedUri()
69: {
70: // FIXME: pass the URI of the cached datum instead
71: // Refactor getBytes() so it loads on demand from the URI
72: try
73: {
74: final Path tempFile = Files.createTempFile("tmp", "image");
75: Files.write(tempFile, bytes);
76: return tempFile.toUri();
77: }
78: catch (IOException e)
79: {
80: throw new RuntimeException(e);
81: }
82: }
83: }