MtasUpdateRequestProcessorResultReader.java.html
9.39 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasUpdateRequestProcessorResultReader.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.solr.update.processor</a> > <span class="el_source">MtasUpdateRequestProcessorResultReader.java</span></div><h1>MtasUpdateRequestProcessorResultReader.java</h1><pre class="source lang-java linenums">package mtas.solr.update.processor;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* The Class MtasUpdateRequestProcessorResultReader.
*/
public class MtasUpdateRequestProcessorResultReader implements Closeable {
/** The Constant log. */
<span class="fc" id="L20"> private static final Log log = LogFactory</span>
<span class="fc" id="L21"> .getLog(MtasUpdateRequestProcessorResultReader.class);</span>
/** The stored string value. */
private String storedStringValue;
/** The file input stream. */
private FileInputStream fileInputStream;
/** The object input stream. */
private ObjectInputStream objectInputStream;
/** The file. */
private File file;
/** The iterator. */
private Iterator<MtasUpdateRequestProcessorResultItem> iterator;
/** The closed. */
private boolean closed;
/**
* Instantiates a new mtas update request processor result reader.
*
* @param fileName the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
public MtasUpdateRequestProcessorResultReader(String fileName)
<span class="fc" id="L48"> throws IOException {</span>
<span class="fc" id="L49"> file = null;</span>
<span class="fc" id="L50"> fileInputStream = null;</span>
<span class="fc" id="L51"> objectInputStream = null;</span>
<span class="fc" id="L52"> closed = false;</span>
<span class="fc" id="L53"> iterator = null;</span>
<span class="pc bpc" id="L54" title="1 of 2 branches missed."> if (fileName != null) {</span>
<span class="fc" id="L55"> file = new File(fileName);</span>
<span class="fc" id="L56"> fileInputStream = new FileInputStream(file);</span>
<span class="fc" id="L57"> objectInputStream = new ObjectInputStream(fileInputStream);</span>
try {
<span class="fc" id="L59"> Object o = objectInputStream.readObject();</span>
<span class="pc bpc" id="L60" title="1 of 2 branches missed."> if (o instanceof String) {</span>
<span class="fc" id="L61"> storedStringValue = (String) o;</span>
} else {
<span class="nc" id="L63"> throw new IOException("invalid tokenStream");</span>
}
<span class="fc" id="L65"> iterator = new Iterator<MtasUpdateRequestProcessorResultItem>() {</span>
<span class="fc" id="L66"> MtasUpdateRequestProcessorResultItem next = null;</span>
@Override
public boolean hasNext() {
<span class="pc bpc" id="L70" title="1 of 2 branches missed."> if (!closed) {</span>
<span class="fc bfc" id="L71" title="All 2 branches covered."> if (next != null) {</span>
<span class="fc" id="L72"> return true;</span>
} else {
<span class="fc" id="L74"> next = getNext(); </span>
<span class="fc bfc" id="L75" title="All 2 branches covered."> return next != null;</span>
}
} else {
<span class="nc" id="L78"> return false;</span>
}
}
@Override
public MtasUpdateRequestProcessorResultItem next() {
<span class="pc bpc" id="L84" title="1 of 2 branches missed."> if (!closed) {</span>
MtasUpdateRequestProcessorResultItem result;
<span class="pc bpc" id="L86" title="1 of 2 branches missed."> if (next != null) {</span>
<span class="fc" id="L87"> result = next;</span>
<span class="fc" id="L88"> next = null;</span>
<span class="fc" id="L89"> return result;</span>
} else {
<span class="nc" id="L91"> next = getNext();</span>
<span class="nc bnc" id="L92" title="All 2 branches missed."> if (next != null) {</span>
<span class="nc" id="L93"> result = next;</span>
<span class="nc" id="L94"> next = null;</span>
<span class="nc" id="L95"> return result;</span>
} else {
<span class="nc" id="L97"> throw new NoSuchElementException();</span>
}
}
} else {
<span class="nc" id="L101"> throw new NoSuchElementException();</span>
}
}
private MtasUpdateRequestProcessorResultItem getNext() {
<span class="pc bpc" id="L106" title="1 of 2 branches missed."> if (!closed) {</span>
try {
<span class="fc" id="L108"> Object o = objectInputStream.readObject();</span>
<span class="pc bpc" id="L109" title="1 of 2 branches missed."> if (o instanceof MtasUpdateRequestProcessorResultItem) {</span>
<span class="fc" id="L110"> return (MtasUpdateRequestProcessorResultItem) o;</span>
} else {
<span class="nc" id="L112"> forceClose();</span>
<span class="nc" id="L113"> return null;</span>
}
<span class="fc" id="L115"> } catch (ClassNotFoundException | IOException e) {</span>
<span class="fc" id="L116"> log.debug(e.getClass().getSimpleName()</span>
+ " while retrieving data from " + fileName, e);
<span class="fc" id="L118"> forceClose();</span>
<span class="fc" id="L119"> return null;</span>
}
} else {
<span class="nc" id="L122"> return null;</span>
}
}
};
<span class="nc" id="L126"> } catch (IOException e) {</span>
<span class="nc" id="L127"> log.error(e.getClass().getSimpleName() + " while processing " + fileName</span>
<span class="nc" id="L128"> + " (" + e.getMessage() + ")", e);</span>
<span class="nc" id="L129"> forceClose();</span>
<span class="nc" id="L130"> throw new IOException(e.getMessage());</span>
<span class="nc" id="L131"> } catch (ClassNotFoundException e) {</span>
<span class="nc" id="L132"> log.error(e.getClass().getSimpleName() + " while processing " + fileName</span>
<span class="nc" id="L133"> + " (" + e.getMessage() + ")", e);</span>
<span class="nc" id="L134"> forceClose();</span>
<span class="nc" id="L135"> throw new IOException("invalid tokenStream");</span>
<span class="fc" id="L136"> }</span>
}
<span class="fc" id="L139"> }</span>
/**
* Gets the stored string value.
*
* @return the stored string value
*/
public String getStoredStringValue() {
<span class="fc" id="L147"> return storedStringValue;</span>
}
/**
* Gets the stored bin value.
*
* @return the stored bin value
*/
public byte[] getStoredBinValue() {
<span class="fc" id="L156"> return new byte[0];</span>
}
/**
* Gets the iterator.
*
* @return the iterator
*/
public Iterator<MtasUpdateRequestProcessorResultItem> getIterator() {
<span class="fc" id="L165"> return iterator;</span>
}
/*
* (non-Javadoc)
*
* @see java.io.Closeable#close()
*/
@Override
public void close() throws IOException {
<span class="fc" id="L175"> forceClose();</span>
<span class="fc" id="L176"> }</span>
/**
* Force close.
*/
private void forceClose() {
<span class="fc bfc" id="L182" title="All 2 branches covered."> if (file != null) {</span>
<span class="pc bpc" id="L183" title="3 of 6 branches missed."> if (file.exists() && file.canWrite() && !file.delete()) {</span>
<span class="nc" id="L184"> log.debug("couldn't delete " + file.getName());</span>
}
<span class="fc" id="L186"> file = null;</span>
}
try {
<span class="fc" id="L189"> objectInputStream.close();</span>
<span class="nc" id="L190"> } catch (IOException e) {</span>
<span class="nc" id="L191"> log.debug(e);</span>
<span class="fc" id="L192"> }</span>
<span class="fc" id="L193"> closed = true;</span>
<span class="fc" id="L194"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>