MtasUpdateRequestProcessorResultWriter.java.html
6.84 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
<?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>MtasUpdateRequestProcessorResultWriter.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">MtasUpdateRequestProcessorResultWriter.java</span></div><h1>MtasUpdateRequestProcessorResultWriter.java</h1><pre class="source lang-java linenums">package mtas.solr.update.processor;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.util.BytesRef;
/**
* The Class MtasUpdateRequestProcessorResultWriter.
*/
public class MtasUpdateRequestProcessorResultWriter implements Closeable {
/** The Constant log. */
<span class="fc" id="L19"> private static final Log log = LogFactory</span>
<span class="fc" id="L20"> .getLog(MtasUpdateRequestProcessorResultWriter.class);</span>
/** The object output stream. */
private ObjectOutputStream objectOutputStream;
/** The file output stream. */
private FileOutputStream fileOutputStream;
/** The closed. */
private boolean closed;
/** The token number. */
private int tokenNumber;
/** The file. */
private File file;
/**
* Instantiates a new mtas update request processor result writer.
*
* @param value the value
*/
<span class="fc" id="L42"> public MtasUpdateRequestProcessorResultWriter(String value) {</span>
<span class="fc" id="L43"> closed = false;</span>
<span class="fc" id="L44"> tokenNumber = 0;</span>
<span class="fc" id="L45"> file = null;</span>
<span class="fc" id="L46"> fileOutputStream = null;</span>
<span class="fc" id="L47"> objectOutputStream = null;</span>
try {
<span class="fc" id="L49"> file = File.createTempFile("MtasUpdateRequestProcessorResult", ".data");</span>
<span class="fc" id="L50"> fileOutputStream = new FileOutputStream(file);</span>
<span class="fc" id="L51"> objectOutputStream = new ObjectOutputStream(fileOutputStream);</span>
<span class="fc" id="L52"> objectOutputStream.writeObject(value);</span>
<span class="nc" id="L53"> } catch (IOException e) {</span>
<span class="nc" id="L54"> forceCloseAndDelete();</span>
<span class="nc" id="L55"> log.debug(e);</span>
<span class="fc" id="L56"> }</span>
<span class="fc" id="L57"> }</span>
/**
* Adds the item.
*
* @param term the term
* @param offsetStart the offset start
* @param offsetEnd the offset end
* @param posIncr the pos incr
* @param payload the payload
* @param flags the flags
*/
public void addItem(String term, Integer offsetStart, Integer offsetEnd,
Integer posIncr, BytesRef payload, Integer flags) {
<span class="pc bpc" id="L71" title="1 of 2 branches missed."> if (!closed) {</span>
<span class="fc" id="L72"> tokenNumber++;</span>
<span class="fc" id="L73"> MtasUpdateRequestProcessorResultItem item = new MtasUpdateRequestProcessorResultItem(</span>
term, offsetStart, offsetEnd, posIncr, payload, flags);
try {
<span class="fc" id="L76"> objectOutputStream.writeObject(item);</span>
<span class="fc" id="L77"> objectOutputStream.reset();</span>
<span class="fc" id="L78"> objectOutputStream.flush();</span>
<span class="nc" id="L79"> } catch (IOException e) {</span>
<span class="nc" id="L80"> forceCloseAndDelete();</span>
<span class="nc" id="L81"> log.debug(e);</span>
<span class="fc" id="L82"> }</span>
}
<span class="fc" id="L84"> }</span>
/**
* Gets the token number.
*
* @return the token number
*/
public int getTokenNumber() {
<span class="fc" id="L92"> return tokenNumber;</span>
}
/**
* Gets the file name.
*
* @return the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
public String getFileName() throws IOException {
<span class="pc bpc" id="L102" title="1 of 2 branches missed."> if (file != null) {</span>
<span class="fc" id="L103"> return file.getAbsolutePath();</span>
} else {
<span class="nc" id="L105"> throw new IOException("no file");</span>
}
}
/*
* (non-Javadoc)
*
* @see java.io.Closeable#close()
*/
@Override
public void close() throws IOException {
<span class="pc bpc" id="L116" title="1 of 2 branches missed."> if (!closed) {</span>
<span class="fc" id="L117"> objectOutputStream.close();</span>
<span class="fc" id="L118"> fileOutputStream.close();</span>
<span class="fc" id="L119"> closed = true;</span>
}
<span class="fc" id="L121"> }</span>
/**
* Force close and delete.
*/
public void forceCloseAndDelete() {
try {
<span class="nc bnc" id="L128" title="All 2 branches missed."> if (objectOutputStream != null) {</span>
<span class="nc" id="L129"> objectOutputStream.close();</span>
<span class="nc" id="L130"> objectOutputStream = null;</span>
}
<span class="nc bnc" id="L132" title="All 2 branches missed."> if (fileOutputStream != null) {</span>
<span class="nc" id="L133"> fileOutputStream.close();</span>
<span class="nc" id="L134"> fileOutputStream = null;</span>
}
<span class="nc" id="L136"> } catch (IOException e) {</span>
<span class="nc" id="L137"> log.debug(e);</span>
<span class="nc" id="L138"> }</span>
<span class="nc" id="L139"> closed = true;</span>
<span class="nc" id="L140"> tokenNumber = 0;</span>
<span class="nc bnc" id="L141" title="All 2 branches missed."> if (file != null) {</span>
<span class="nc bnc" id="L142" title="All 6 branches missed."> if (file.exists() && file.canWrite() && !file.delete()) {</span>
<span class="nc" id="L143"> log.debug("couldn't delete " + file.getName());</span>
}
<span class="nc" id="L145"> file = null;</span>
}
<span class="nc" id="L147"> }</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>