1818
1919import java .io .IOException ;
2020
21- import org . apache . commons . codec . binary . Base64 ;
21+ import javax . xml . bind . DatatypeConverter ;
2222
2323import org .apache .lucene .util .Bits ;
2424import org .apache .lucene .util .BytesRef ;
@@ -117,40 +117,41 @@ public void handleRequestBody(final SolrQueryRequest req, final SolrQueryRespons
117117 tmp = te .next ();
118118 }
119119
120- String text ;
121- String [] vals ;
122- String docPartition ;
123- String vsn ;
124- String riakBType ;
125- String riakBName ;
126- String riakKey ;
127- String hash ;
128120 int count = 0 ;
129121 BytesRef current = null ;
130122 final Bits liveDocs = rdr .getLiveDocs ();
131123
132124 while (!endOfItr (tmp ) && count < n ) {
133125 if (isLive (liveDocs , te )) {
134126 current = BytesRef .deepCopyOf (tmp );
135- text = tmp .utf8ToString ();
127+ final String text = tmp .utf8ToString ();
136128 if (log .isDebugEnabled ()) {
137129 log .debug ("text: " + text );
138130 }
139- vals = text .split (" " );
131+ final String [] vals = text .split (" " );
140132
141- vsn = vals [0 ];
142- docPartition = vals [1 ];
143- riakBType = decodeBase64DocPart (vals [2 ]);
144- riakBName = decodeBase64DocPart (vals [3 ]);
145- riakKey = decodeBase64DocPart (vals [4 ]);
146- hash = vals [5 ];
133+ final String docPartition = vals [1 ];
147134
135+ /*
136+ If the partition matches the one we are looking for,
137+ parse the version, bkey, and object hash from the
138+ entropy data field (term).
139+ */
148140 if (partition .equals (docPartition )) {
149- SolrDocument tmpDoc = new SolrDocument ();
141+ final String vsn = vals [0 ];
142+
143+ final String [] decoded = decodeForVersion (vsn ,
144+ vals [2 ],
145+ vals [3 ],
146+ vals [4 ]);
147+
148+ final String hash = vals [5 ];
149+
150+ final SolrDocument tmpDoc = new SolrDocument ();
150151 tmpDoc .addField ("vsn" , vsn );
151- tmpDoc .addField ("riak_bucket_type" , riakBType );
152- tmpDoc .addField ("riak_bucket_name" , riakBName );
153- tmpDoc .addField ("riak_key" , riakKey );
152+ tmpDoc .addField ("riak_bucket_type" , decoded [ 0 ] );
153+ tmpDoc .addField ("riak_bucket_name" , decoded [ 1 ] );
154+ tmpDoc .addField ("riak_key" , decoded [ 2 ] );
154155 tmpDoc .addField ("base64_hash" , hash );
155156 docs .add (tmpDoc );
156157 count ++;
@@ -163,7 +164,8 @@ public void handleRequestBody(final SolrQueryRequest req, final SolrQueryRespons
163164 rsp .add ("more" , false );
164165 } else {
165166 rsp .add ("more" , true );
166- final String newCont = Base64 .encodeBase64URLSafeString (current .bytes );
167+ final String newCont =
168+ org .apache .commons .codec .binary .Base64 .encodeBase64URLSafeString (current .bytes );
167169 // The continue context for next req to start where
168170 // this one finished.
169171 rsp .add ("continuation" , newCont );
@@ -182,7 +184,7 @@ static boolean isLive(final Bits liveDocs, final TermsEnum te) throws IOExceptio
182184 }
183185
184186 static BytesRef decodeCont (final String cont ) {
185- final byte [] bytes = Base64 .decodeBase64 (cont );
187+ final byte [] bytes = org . apache . commons . codec . binary . Base64 .decodeBase64 (cont );
186188 return new BytesRef (bytes );
187189 }
188190
@@ -209,12 +211,38 @@ public String getSource() {
209211 return "TODO: implement getSource" ;
210212 }
211213
214+ /**
215+ @param vsn a String vsn number referring to the item's ed handler version
216+ @param riakBType riak bucket-type
217+ @param riakBName riak bucket-name
218+ @param riakKey riak key
219+ @return a String array consisting of a Bucket Type, Bucket Name, and Riak Key
220+ */
221+ private String [] decodeForVersion (String vsn , String riakBType , String riakBName , String riakKey ) {
222+ final String [] bKeyInfo ;
223+ switch (Integer .parseInt (vsn )) {
224+ case 1 :
225+ bKeyInfo = new String [] {riakBType , riakBName , riakKey };
226+ break ;
227+ default :
228+ bKeyInfo = new String []
229+ {
230+ decodeBase64DocPart (riakBType ),
231+ decodeBase64DocPart (riakBName ),
232+ decodeBase64DocPart (riakKey )
233+ };
234+ break ;
235+ }
236+ return bKeyInfo ;
237+ }
238+
212239 /**
213240 @param base64EncodedVal base64 encoded string
214241 @return a string of decoded base64 bytes
215- */
242+ */
216243 private String decodeBase64DocPart (String base64EncodedVal ) {
217- byte [] bytes = Base64 . decodeBase64 ( base64EncodedVal );
218- return new String ( bytes );
244+ return new String ( DatatypeConverter . parseBase64Binary (
245+ base64EncodedVal ) );
219246 }
220247}
248+
0 commit comments