private readonly short[][] costs; // array is backward IDs first since get is called using the same backward ID consecutively. maybe doesn't matter. private ConnectionCosts() { short[][] costs = null; using (Stream @is = BinaryDictionary.GetTypeResource(GetType(), FILENAME_SUFFIX)) { DataInput @in = new InputStreamDataInput(@is); CodecUtil.CheckHeader(@in, HEADER, VERSION, VERSION); int forwardSize = @in.ReadVInt32(); int backwardSize = @in.ReadVInt32(); costs = RectangularArrays.ReturnRectangularArray <short>(backwardSize, forwardSize); int accum = 0; for (int j = 0; j < costs.Length; j++) { short[] a = costs[j]; for (int i = 0; i < a.Length; i++) { int raw = @in.ReadVInt32(); accum += ((int)((uint)raw) >> 1) ^ -(raw & 1); a[i] = (short)accum; } } } this.costs = costs; }
public int[] GetMap() { if (map != null) { return(map); } AddDone(); // in case this wasn't previously called var ifs = new FileStream(tmpfile, FileMode.OpenOrCreate, FileAccess.Read); var @in = new InputStreamDataInput(ifs); map = new int[@in.ReadInt32()]; // NOTE: The current code assumes here that the map is complete, // i.e., every ordinal gets one and exactly one value. Otherwise, // we may run into an EOF here, or vice versa, not read everything. for (int i = 0; i < map.Length; i++) { int origordinal = @in.ReadInt32(); int newordinal = @in.ReadInt32(); map[origordinal] = newordinal; } @in.Dispose(); // Delete the temporary file, which is no longer needed. if (File.Exists(tmpfile)) { File.Delete(tmpfile); } return(map); }
/// <summary> /// Calls <see cref="Load(DataInput)"/> after converting /// <see cref="Stream"/> to <see cref="DataInput"/> /// </summary> public virtual bool Load(Stream input) { DataInput dataIn = new InputStreamDataInput(input); try { return(Load(dataIn)); } finally { IOUtils.Dispose(input); } }
private CharacterDefinition() { using Stream @is = BinaryDictionary.GetTypeResource(GetType(), FILENAME_SUFFIX); DataInput @in = new InputStreamDataInput(@is); CodecUtil.CheckHeader(@in, HEADER, VERSION, VERSION); @in.ReadBytes(characterCategoryMap, 0, characterCategoryMap.Length); for (int i = 0; i < CLASS_COUNT; i++) { byte b = @in.ReadByte(); invokeMap[i] = (b & 0x01) != 0; groupMap[i] = (b & 0x02) != 0; } }
protected BinaryDictionary() { int[] targetMapOffsets = null, targetMap = null; string[] posDict = null; string[] inflFormDict = null; string[] inflTypeDict = null; ByteBuffer buffer; // LUCENENET: IDE0059: Remove unnecessary value assignment using (Stream mapIS = GetResource(TARGETMAP_FILENAME_SUFFIX)) { DataInput @in = new InputStreamDataInput(mapIS); CodecUtil.CheckHeader(@in, TARGETMAP_HEADER, VERSION, VERSION); targetMap = new int[@in.ReadVInt32()]; targetMapOffsets = new int[@in.ReadVInt32()]; int accum = 0, sourceId = 0; for (int ofs = 0; ofs < targetMap.Length; ofs++) { int val = @in.ReadVInt32(); if ((val & 0x01) != 0) { targetMapOffsets[sourceId] = ofs; sourceId++; } accum += val.TripleShift(1); targetMap[ofs] = accum; } if (sourceId + 1 != targetMapOffsets.Length) { throw new IOException("targetMap file format broken"); } targetMapOffsets[sourceId] = targetMap.Length; } using (Stream posIS = GetResource(POSDICT_FILENAME_SUFFIX)) { DataInput @in = new InputStreamDataInput(posIS); CodecUtil.CheckHeader(@in, POSDICT_HEADER, VERSION, VERSION); int posSize = @in.ReadVInt32(); posDict = new string[posSize]; inflTypeDict = new string[posSize]; inflFormDict = new string[posSize]; for (int j = 0; j < posSize; j++) { posDict[j] = @in.ReadString(); inflTypeDict[j] = @in.ReadString(); inflFormDict[j] = @in.ReadString(); // this is how we encode null inflections if (inflTypeDict[j].Length == 0) { inflTypeDict[j] = null; } if (inflFormDict[j].Length == 0) { inflFormDict[j] = null; } } } ByteBuffer tmpBuffer; using (Stream dictIS = GetResource(DICT_FILENAME_SUFFIX)) { // no buffering here, as we load in one large buffer DataInput @in = new InputStreamDataInput(dictIS); CodecUtil.CheckHeader(@in, DICT_HEADER, VERSION, VERSION); int size = @in.ReadVInt32(); tmpBuffer = ByteBuffer.Allocate(size); // AllocateDirect..? int read = dictIS.Read(tmpBuffer.Array, 0, size); if (read != size) { throw EOFException.Create("Cannot read whole dictionary"); } } buffer = tmpBuffer.AsReadOnlyBuffer(); this.targetMap = targetMap; this.targetMapOffsets = targetMapOffsets; this.posDict = posDict; this.inflTypeDict = inflTypeDict; this.inflFormDict = inflFormDict; this.buffer = buffer; }