//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override public int nextPosition() throws java.io.IOException public override int nextPosition() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int token = postingInput.readVInt(); int token = postingInput.readVInt(); pos += (int)((uint)token >> 1); if (storeOffsets) { startOffset_Renamed = endOffset_Renamed + postingInput.readVInt(); endOffset_Renamed = startOffset_Renamed + postingInput.readVInt(); } if ((token & 1) != 0) { payload.offset = 0; payload.length = postingInput.readVInt(); if (payload.length > payload.bytes.length) { payload.bytes = new sbyte[ArrayUtil.oversize(payload.length, 1)]; } postingInput.readBytes(payload.bytes, 0, payload.length); } else { payload.length = 0; } return(pos); }
public override void lookupOrd(long ord, BytesRef result) { try { if (ord < 0 || ord >= field.numValues) { throw new System.IndexOutOfRangeException("ord must be 0 .. " + (field.numValues - 1) + "; got " + ord); } @in.seek(field.dataStartFilePointer + ord * (9 + field.pattern.Length + field.maxLength)); SimpleTextUtil.ReadLine(@in, scratch); Debug.Assert(StringHelper.StartsWith(scratch, LENGTH), "got " + scratch.utf8ToString() + " in=" + @in); int len; try { len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)); } catch (ParseException pe) { CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")"); e.initCause(pe); throw e; } result.bytes = new sbyte[len]; result.offset = 0; result.length = len; @in.readBytes(result.bytes, 0, len); } catch (IOException ioe) { throw new Exception(ioe); } }
public override bool get(int index) { try { @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * index); SimpleTextUtil.ReadLine(@in, scratch); Debug.Assert(StringHelper.StartsWith(scratch, LENGTH)); int len; try { len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)); } catch (ParseException pe) { CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")"); e.initCause(pe); throw e; } // skip past bytes sbyte[] bytes = new sbyte[len]; @in.readBytes(bytes, 0, len); SimpleTextUtil.ReadLine(@in, scratch); // newline SimpleTextUtil.ReadLine(@in, scratch); // 'T' or 'F' return(scratch.bytes[scratch.offset] == (sbyte)'T'); } catch (IOException ioe) { throw new Exception(ioe); } }
public override void get(int docID, BytesRef result) { try { if (docID < 0 || docID >= outerInstance.maxDoc) { throw new System.IndexOutOfRangeException("docID must be 0 .. " + (outerInstance.maxDoc - 1) + "; got " + docID); } @in.seek(field.dataStartFilePointer + (9 + field.pattern.Length + field.maxLength + 2) * docID); SimpleTextUtil.ReadLine(@in, scratch); Debug.Assert(StringHelper.StartsWith(scratch, LENGTH)); int len; try { len = (int)decoder.parse(new string(scratch.bytes, scratch.offset + LENGTH.length, scratch.length - LENGTH.length, StandardCharsets.UTF_8)); } catch (ParseException pe) { CorruptIndexException e = new CorruptIndexException("failed to parse int length (resource=" + @in + ")"); e.initCause(pe); throw e; } result.bytes = new sbyte[len]; result.offset = 0; result.length = len; @in.readBytes(result.bytes, 0, len); } catch (IOException ioe) { throw new Exception(ioe); } }
public override void readBytes(byte[] b, int offset, int len) { _indexInput.readBytes(b, offset, len); }
public static void Main(string[] args) { string filename = null; bool extract = false; string dirImpl = null; int j = 0; while (j < args.Length) { string arg = args[j]; if ("-extract".Equals(arg)) { extract = true; } else if ("-dir-impl".Equals(arg)) { if (j == args.Length - 1) { Console.WriteLine("ERROR: missing value for -dir-impl option"); Environment.Exit(1); } j++; dirImpl = args[j]; } else if (filename == null) { filename = arg; } j++; } if (filename == null) { Console.WriteLine("Usage: org.apache.lucene.index.CompoundFileExtractor [-extract] [-dir-impl X] <cfsfile>"); return; } Directory dir = null; CompoundFileDirectory cfr = null; IOContext context = IOContext.READ; try { File file = new File(filename); string dirname = file.AbsoluteFile.Parent; filename = file.Name; if (dirImpl == null) { dir = FSDirectory.open(new File(dirname)); } else { dir = CommandLineUtil.newFSDirectory(dirImpl, new File(dirname)); } cfr = new CompoundFileDirectory(dir, filename, IOContext.DEFAULT, false); string[] files = cfr.listAll(); ArrayUtil.timSort(files); // sort the array of filename so that the output is more readable for (int i = 0; i < files.Length; ++i) { long len = cfr.fileLength(files[i]); if (extract) { Console.WriteLine("extract " + files[i] + " with " + len + " bytes to local directory..."); IndexInput ii = cfr.openInput(files[i], context); FileOutputStream f = new FileOutputStream(files[i]); // read and write with a small buffer, which is more effective than reading byte by byte sbyte[] buffer = new sbyte[1024]; int chunk = buffer.Length; while (len > 0) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int bufLen = (int) Math.min(chunk, len); int bufLen = (int)Math.Min(chunk, len); ii.readBytes(buffer, 0, bufLen); f.write(buffer, 0, bufLen); len -= bufLen; } f.close(); ii.close(); } else { Console.WriteLine(files[i] + ": " + len + " bytes"); } } } catch (IOException ioe) { Console.WriteLine(ioe.ToString()); Console.Write(ioe.StackTrace); } finally { try { if (dir != null) { dir.close(); } if (cfr != null) { cfr.close(); } } catch (IOException ioe) { Console.WriteLine(ioe.ToString()); Console.Write(ioe.StackTrace); } } }