Skip to content

Package: FileImageModelHolder

FileImageModelHolder

nameinstructionbranchcomplexitylinemethod
FileImageModelHolder()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
get()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
readExternal(ObjectInput)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
set(ImageModel)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
writeExternal(ObjectOutput)
M: 35 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 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/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.image.processor;
28:
29: import java.io.IOException;
30: import java.io.ObjectInput;
31: import java.io.ObjectInputStream;
32: import java.io.ObjectOutput;
33: import java.io.ObjectOutputStream;
34: import java.io.Serializable;
35: import java.nio.file.Files;
36: import java.nio.file.Path;
37: import it.tidalwave.image.ImageModel;
38: import it.tidalwave.image.ImageModelHolder;
39:
40: /***********************************************************************************************************************
41: *
42: * @author Fabrizio Giudici
43: *
44: **********************************************************************************************************************/
45: /* package */ class FileImageModelHolder extends ImageModelHolder
46: {
47: private Serializable id;
48:
49: private Path file;
50:
51: private transient ImageModel imageModel;
52:
53: /*******************************************************************************************************************
54: *
55: *
56: ******************************************************************************************************************/
57: public FileImageModelHolder()
58: {
59: }
60:
61: /*******************************************************************************************************************
62: *
63: *
64: ******************************************************************************************************************/
65: @Override
66: public synchronized ImageModel get()
67: {
68:• if (imageModel == null)
69: {
70: try (final var ois = new ObjectInputStream(Files.newInputStream(file)))
71: {
72: imageModel = (ImageModel)ois.readObject();
73: }
74: catch (Exception e)
75: {
76: throw new RuntimeException(e);
77: }
78: }
79:
80: return imageModel;
81: }
82:
83: /*******************************************************************************************************************
84: *
85: *
86: ******************************************************************************************************************/
87: @Override
88: public void set (final ImageModel imageModel)
89: {
90: this.imageModel = imageModel;
91: this.id = imageModel.getId();
92: }
93:
94: /*******************************************************************************************************************
95: *
96: *
97: ******************************************************************************************************************/
98: public void writeExternal (final ObjectOutput out)
99: throws IOException
100: {
101:• if (file == null)
102: {
103: file = Path.of("HOLDER-" + id);
104: // FIXME: be sure to create the file in a place where it will not be added in
105: // the job result .zip. But I don't know if /tmp is shared among nodes in the grid.
106: final var oos = new ObjectOutputStream(Files.newOutputStream(file));
107: oos.writeObject(imageModel);
108: oos.close();
109: }
110:
111: out.writeObject(id);
112: out.writeObject(file);
113: }
114:
115: /*******************************************************************************************************************
116: *
117: *
118: ******************************************************************************************************************/
119: public void readExternal (final ObjectInput in)
120: throws IOException, ClassNotFoundException
121: {
122: id = (Serializable)in.readObject();
123: file = (Path)in.readObject();
124: }
125: }