/// <exception cref="System.IO.IOException"/> private void ProcessINodeDirectoryAttributes(DataInputStream @in, ImageVisitor v, string parentName) { string pathName = ReadINodePath(@in, parentName); v.Visit(ImageVisitor.ImageElement.InodePath, pathName); ProcessPermission(@in, v); v.Visit(ImageVisitor.ImageElement.ModificationTime, FormatDate(@in.ReadLong())); v.Visit(ImageVisitor.ImageElement.NsQuota, @in.ReadLong()); v.Visit(ImageVisitor.ImageElement.DsQuota, @in.ReadLong()); }
/// <summary> /// 读取文件列表 /// </summary> /// /// <param name="dis"></param> /// <param name="fileTableNumber"></param> /// <returns></returns> /// <exception cref="System.Exception"></exception> public static LPKTable[] ReadLPKTable(DataInputStream dis, int fileTableNumber) { LPKTable[] fileTable = new LPKTable[fileTableNumber]; for (int i = 0; i < fileTableNumber; i++) { LPKTable ft = new LPKTable(); ft.SetFileName(ReadByteArray(dis, LPKHeader.LF_FILE_LENGTH)); ft.SetFileSize(dis.ReadLong()); ft.SetOffSet(dis.ReadLong()); fileTable[i] = ft; } return(fileTable); }
/* (non-Javadoc) * @see org.gogpsproject.Streamable#read(java.io.DataInputStream) */ public void read(DataInputStream dai, bool oldVersion) { int v = 1; if (!oldVersion) { v = dai.ReadInt(); } if (v == 1) { long l = dai.ReadLong(); refTime = new Time(l > 0 ? l : GetCurrentMilli()); satID = dai.Read(); week = dai.ReadInt(); L2Code = dai.ReadInt(); L2Flag = dai.ReadInt(); svAccur = dai.ReadInt(); svHealth = dai.ReadInt(); iode = dai.ReadInt(); iodc = dai.ReadInt(); toc = dai.ReadDouble(); toe = dai.ReadDouble(); af0 = dai.ReadDouble(); af1 = dai.ReadDouble(); af2 = dai.ReadDouble(); tgd = dai.ReadDouble(); rootA = dai.ReadDouble(); e = dai.ReadDouble(); i0 = dai.ReadDouble(); iDot = dai.ReadDouble(); omega = dai.ReadDouble(); omega0 = dai.ReadDouble(); omegaDot = dai.ReadDouble(); M0 = dai.ReadDouble(); deltaN = dai.ReadDouble(); crc = dai.ReadDouble(); crs = dai.ReadDouble(); cuc = dai.ReadDouble(); cus = dai.ReadDouble(); cic = dai.ReadDouble(); cis = dai.ReadDouble(); fitInt = dai.ReadLong(); } else { throw new IOException("Unknown format version:" + v); } }
/// <exception cref="System.IO.IOException"/> private void ProcessTokenAddOrUpdate(ChildData data) { ByteArrayInputStream bin = new ByteArrayInputStream(data.GetData()); DataInputStream din = new DataInputStream(bin); TokenIdent ident = CreateIdentifier(); ident.ReadFields(din); long renewDate = din.ReadLong(); int pwdLen = din.ReadInt(); byte[] password = new byte[pwdLen]; int numRead = din.Read(password, 0, pwdLen); if (numRead > -1) { AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo = new AbstractDelegationTokenSecretManager.DelegationTokenInformation (renewDate, password); lock (this) { currentTokens[ident] = tokenInfo; // The cancel task might be waiting Runtime.NotifyAll(this); } } }
// INode /// <exception cref="System.IO.IOException"/> private void ProcessINodeFileAttributes(DataInputStream @in, ImageVisitor v, string parentName) { string pathName = ReadINodePath(@in, parentName); v.Visit(ImageVisitor.ImageElement.InodePath, pathName); ProcessPermission(@in, v); v.Visit(ImageVisitor.ImageElement.ModificationTime, FormatDate(@in.ReadLong())); if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.FileAccessTime, imageVersion )) { v.Visit(ImageVisitor.ImageElement.AccessTime, FormatDate(@in.ReadLong())); } v.Visit(ImageVisitor.ImageElement.Replication, @in.ReadShort()); v.Visit(ImageVisitor.ImageElement.BlockSize, @in.ReadLong()); }
public void read(DataInputStream dai, bool oldVersion) { int v = dai.ReadInt(); if (v == 1) { long l = dai.ReadLong(); refTime = l == -1 ? null : new Time(l); for (int i = 0; i < 3; i++) { ecef.set(i, dai.ReadDouble()); } for (int i = 0; i < 3; i++) { enu.set(i, dai.ReadDouble()); } for (int i = 0; i < 3; i++) { geod.set(i, dai.ReadDouble()); } } else { throw new IOException("Unknown format version:" + v); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static long[] readLongArray(java.io.DataInputStream dis, int count) throws java.io.IOException private static long[] ReadLongArray(DataInputStream dis, int count) { long[] ret = new long[count]; for (int i = 0; i < count; i++) { ret[i] = dis.ReadLong(); } return(ret); }
private void HandleSynchronization(DataInputStream dataInputStream, model.RtpMidiServer rtpMidiServer) { int ssrc = dataInputStream.ReadInt(); byte count = (byte)dataInputStream.ReadByte(); int paddingBytes = dataInputStream.Read(new byte[NUMBER_OF_PADDING_BYTES]); if (paddingBytes != NUMBER_OF_PADDING_BYTES) { Log.Info("RtpMidi", "The number of padding bytes: {} did not match: {}", paddingBytes, NUMBER_OF_PADDING_BYTES); return; } long timestamp1 = dataInputStream.ReadLong(); long timestamp2 = dataInputStream.ReadLong(); long timestamp3 = dataInputStream.ReadLong(); foreach (IRtpMidiCommandListener listener in listeners) { listener.OnClockSynchronization(new RtpMidiClockSynchronization(ssrc, count, timestamp1, timestamp2, timestamp3), rtpMidiServer); } }
/// <summary> /// 读取头文件 /// </summary> /// /// <param name="dis"></param> /// <returns></returns> /// <exception cref="System.Exception"></exception> public static LPKHeader ReadHeader(DataInputStream dis) { LPKHeader header = new LPKHeader(); header.SetPAKIdentity(dis.ReadInt()); byte[] pass = ReadByteArray(dis, LPKHeader.LF_PASSWORD_LENGTH); header.SetPassword(pass); header.SetVersion(dis.ReadFloat()); header.SetTables(dis.ReadLong()); return(header); }
/* (non-Javadoc) * @see org.gogpsproject.Streamable#write(java.io.DataOutputStream) */ public void read(DataInputStream dai, bool oldVersion) { int v = 1; if (!oldVersion) { v = dai.ReadInt(); } if (v == 1) { health = dai.ReadLong(); utcA1 = dai.ReadDouble(); utcA0 = dai.ReadDouble(); utcTOW = dai.ReadLong(); utcWNT = dai.ReadInt(); utcLS = dai.ReadInt(); utcWNF = dai.ReadInt(); utcDN = dai.ReadInt(); utcLSF = dai.ReadInt(); for (int i = 0; i < alpha.Count(); i++) { alpha[i] = dai.ReadFloat(); } for (int i = 0; i < beta.Count(); i++) { beta[i] = dai.ReadFloat(); } validHealth = dai.ReadBoolean(); validUTC = dai.ReadBoolean(); validKlobuchar = dai.ReadBoolean(); long l = dai.ReadLong(); refTime = new Time(l > 0 ? l : JavaSystem.CurrentTimeMillis()); } else { throw new IOException("Unknown format version:" + v); } }
// INodesUnderConstruction /// <summary>Process the blocks section of the fsimage.</summary> /// <param name="in">Datastream to process</param> /// <param name="v">Visitor to walk over inodes</param> /// <param name="skipBlocks">Walk over each block?</param> /// <exception cref="System.IO.IOException"/> private void ProcessBlocks(DataInputStream @in, ImageVisitor v, int numBlocks, bool skipBlocks) { v.VisitEnclosingElement(ImageVisitor.ImageElement.Blocks, ImageVisitor.ImageElement .NumBlocks, numBlocks); // directory or symlink or reference node, no blocks to process if (numBlocks < 0) { v.LeaveEnclosingElement(); // Blocks return; } if (skipBlocks) { int bytesToSkip = ((long.Size * 3) / 8) * numBlocks; /* fields */ /*bits*/ if (@in.SkipBytes(bytesToSkip) != bytesToSkip) { throw new IOException("Error skipping over blocks"); } } else { for (int j = 0; j < numBlocks; j++) { v.VisitEnclosingElement(ImageVisitor.ImageElement.Block); v.Visit(ImageVisitor.ImageElement.BlockId, @in.ReadLong()); v.Visit(ImageVisitor.ImageElement.NumBytes, @in.ReadLong()); v.Visit(ImageVisitor.ImageElement.GenerationStamp, @in.ReadLong()); v.LeaveEnclosingElement(); } } // Block v.LeaveEnclosingElement(); }
/// <summary>Process the Delegation Token related section in fsimage.</summary> /// <param name="in">DataInputStream to process</param> /// <param name="v">Visitor to walk over records</param> /// <exception cref="System.IO.IOException"/> private void ProcessDelegationTokens(DataInputStream @in, ImageVisitor v) { v.Visit(ImageVisitor.ImageElement.CurrentDelegationKeyId, @in.ReadInt()); int numDKeys = @in.ReadInt(); v.VisitEnclosingElement(ImageVisitor.ImageElement.DelegationKeys, ImageVisitor.ImageElement .NumDelegationKeys, numDKeys); for (int i = 0; i < numDKeys; i++) { DelegationKey key = new DelegationKey(); key.ReadFields(@in); v.Visit(ImageVisitor.ImageElement.DelegationKey, key.ToString()); } v.LeaveEnclosingElement(); v.Visit(ImageVisitor.ImageElement.DelegationTokenSequenceNumber, @in.ReadInt()); int numDTokens = @in.ReadInt(); v.VisitEnclosingElement(ImageVisitor.ImageElement.DelegationTokens, ImageVisitor.ImageElement .NumDelegationTokens, numDTokens); for (int i_1 = 0; i_1 < numDTokens; i_1++) { DelegationTokenIdentifier id = new DelegationTokenIdentifier(); id.ReadFields(@in); long expiryTime = @in.ReadLong(); v.VisitEnclosingElement(ImageVisitor.ImageElement.DelegationTokenIdentifier); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierKind, id.GetKind().ToString ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierSeqno, id.GetSequenceNumber ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierOwner, id.GetOwner().ToString ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierRenewer, id.GetRenewer ().ToString()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierRealuser, id.GetRealUser ().ToString()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierIssueDate, id.GetIssueDate ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierMaxDate, id.GetMaxDate ()); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierExpiryTime, expiryTime ); v.Visit(ImageVisitor.ImageElement.DelegationTokenIdentifierMasterKeyId, id.GetMasterKeyId ()); v.LeaveEnclosingElement(); } // DELEGATION_TOKEN_IDENTIFIER v.LeaveEnclosingElement(); }
public override void Unmarshal(DataInputStream dis) { base.Unmarshal(dis); if (dis != null) { try { this._environmentalSimulationApplicationID.Unmarshal(dis); this._fieldNumber = dis.ReadUnsignedShort(); this._pduNumber = dis.ReadUnsignedShort(); this._pduTotal = dis.ReadUnsignedShort(); this._coordinateSystem = dis.ReadUnsignedShort(); this._numberOfGridAxes = dis.ReadUnsignedByte(); this._constantGrid = dis.ReadUnsignedByte(); this._environmentType.Unmarshal(dis); this._orientation.Unmarshal(dis); this._sampleTime = dis.ReadLong(); this._totalValues = dis.ReadUnsignedInt(); this._vectorDimension = dis.ReadUnsignedByte(); this._padding1 = dis.ReadUnsignedShort(); this._padding2 = dis.ReadUnsignedByte(); for (int idx = 0; idx < this.NumberOfGridAxes; idx++) { GridAxisRecord anX = new GridAxisRecord(); anX.Unmarshal(dis); this._gridDataList.Add(anX); } } catch (Exception e) { if (PduBase.TraceExceptions) { Trace.WriteLine(e); Trace.Flush(); } this.RaiseExceptionOccured(e); if (PduBase.ThrowExceptions) { throw e; } } } }
/// <exception cref="System.IO.IOException"/> private void LoadToken(HistoryServerStateStoreService.HistoryServerState state, byte [] data) { MRDelegationTokenIdentifier tokenId = new MRDelegationTokenIdentifier(); long renewDate; DataInputStream @in = new DataInputStream(new ByteArrayInputStream(data)); try { tokenId.ReadFields(@in); renewDate = @in.ReadLong(); } finally { IOUtils.Cleanup(Log, @in); } state.tokenState[tokenId] = renewDate; }
public virtual void Unmarshal(DataInputStream dis) { if (dis != null) { try { this._expendableType.Unmarshal(dis); this._padding = dis.ReadLong(); } catch (Exception e) { #if DEBUG Trace.WriteLine(e); Trace.Flush(); #endif this.OnException(e); } } }
/// <summary>Process CacheManager state from the fsimage.</summary> /// <exception cref="System.IO.IOException"/> private void ProcessCacheManagerState(DataInputStream @in, ImageVisitor v) { v.Visit(ImageVisitor.ImageElement.CacheNextEntryId, @in.ReadLong()); int numPools = @in.ReadInt(); for (int i = 0; i < numPools; i++) { v.Visit(ImageVisitor.ImageElement.CachePoolName, Text.ReadString(@in)); ProcessCachePoolPermission(@in, v); v.Visit(ImageVisitor.ImageElement.CachePoolWeight, @in.ReadInt()); } int numEntries = @in.ReadInt(); for (int i_1 = 0; i_1 < numEntries; i_1++) { v.Visit(ImageVisitor.ImageElement.CacheEntryPath, Text.ReadString(@in)); v.Visit(ImageVisitor.ImageElement.CacheEntryReplication, @in.ReadShort()); v.Visit(ImageVisitor.ImageElement.CacheEntryPoolName, Text.ReadString(@in)); } }
/// <summary>Determine the checkpoint time of the specified StorageDirectory</summary> /// <param name="sd">StorageDirectory to check</param> /// <returns>If file exists and can be read, last checkpoint time. If not, 0L.</returns> /// <exception cref="System.IO.IOException">On errors processing file pointed to by sd /// </exception> internal static long ReadCheckpointTime(Storage.StorageDirectory sd) { FilePath timeFile = NNStorage.GetStorageFile(sd, NNStorage.NameNodeFile.Time); long timeStamp = 0L; if (timeFile.Exists() && FileUtil.CanRead(timeFile)) { DataInputStream @in = new DataInputStream(new FileInputStream(timeFile)); try { timeStamp = @in.ReadLong(); @in.Close(); @in = null; } finally { IOUtils.Cleanup(Log, @in); } } return(timeStamp); }
/// <exception cref="System.IO.IOException"/> private MRDelegationTokenIdentifier LoadToken(HistoryServerStateStoreService.HistoryServerState state, Path tokenFile, long numTokenFileBytes) { MRDelegationTokenIdentifier tokenId = new MRDelegationTokenIdentifier(); long renewDate; byte[] tokenData = ReadFile(tokenFile, numTokenFileBytes); DataInputStream @in = new DataInputStream(new ByteArrayInputStream(tokenData)); try { tokenId.ReadFields(@in); renewDate = @in.ReadLong(); } finally { IOUtils.Cleanup(Log, @in); } state.tokenState[tokenId] = renewDate; return(tokenId); }
// DELEGATION_TOKENS /// <summary>Process the INodes under construction section of the fsimage.</summary> /// <param name="in">DataInputStream to process</param> /// <param name="v">Visitor to walk over inodes</param> /// <param name="skipBlocks">Walk over each block?</param> /// <exception cref="System.IO.IOException"/> private void ProcessINodesUC(DataInputStream @in, ImageVisitor v, bool skipBlocks ) { int numINUC = @in.ReadInt(); v.VisitEnclosingElement(ImageVisitor.ImageElement.InodesUnderConstruction, ImageVisitor.ImageElement .NumInodesUnderConstruction, numINUC); for (int i = 0; i < numINUC; i++) { v.VisitEnclosingElement(ImageVisitor.ImageElement.InodeUnderConstruction); byte[] name = FSImageSerialization.ReadBytes(@in); string n = Sharpen.Runtime.GetStringForBytes(name, "UTF8"); v.Visit(ImageVisitor.ImageElement.InodePath, n); if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddInodeId, imageVersion )) { long inodeId = @in.ReadLong(); v.Visit(ImageVisitor.ImageElement.InodeId, inodeId); } v.Visit(ImageVisitor.ImageElement.Replication, @in.ReadShort()); v.Visit(ImageVisitor.ImageElement.ModificationTime, FormatDate(@in.ReadLong())); v.Visit(ImageVisitor.ImageElement.PreferredBlockSize, @in.ReadLong()); int numBlocks = @in.ReadInt(); ProcessBlocks(@in, v, numBlocks, skipBlocks); ProcessPermission(@in, v); v.Visit(ImageVisitor.ImageElement.ClientName, FSImageSerialization.ReadString(@in )); v.Visit(ImageVisitor.ImageElement.ClientMachine, FSImageSerialization.ReadString( @in)); // Skip over the datanode descriptors, which are still stored in the // file but are not used by the datanode or loaded into memory int numLocs = @in.ReadInt(); for (int j = 0; j < numLocs; j++) { @in.ReadShort(); @in.ReadLong(); @in.ReadLong(); @in.ReadLong(); @in.ReadInt(); FSImageSerialization.ReadString(@in); FSImageSerialization.ReadString(@in); WritableUtils.ReadEnum <DatanodeInfo.AdminStates>(@in); } v.LeaveEnclosingElement(); } // INodeUnderConstruction v.LeaveEnclosingElement(); }
/// <exception cref="System.IO.IOException"/> private AbstractDelegationTokenSecretManager.DelegationTokenInformation GetTokenInfoFromZK (TokenIdent ident, bool quiet) { string nodePath = GetNodePath(ZkDtsmTokensRoot, DelegationTokenPrefix + ident.GetSequenceNumber ()); try { byte[] data = zkClient.GetData().ForPath(nodePath); if ((data == null) || (data.Length == 0)) { return(null); } ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin); CreateIdentifier().ReadFields(din); long renewDate = din.ReadLong(); int pwdLen = din.ReadInt(); byte[] password = new byte[pwdLen]; int numRead = din.Read(password, 0, pwdLen); if (numRead > -1) { AbstractDelegationTokenSecretManager.DelegationTokenInformation tokenInfo = new AbstractDelegationTokenSecretManager.DelegationTokenInformation (renewDate, password); return(tokenInfo); } } catch (KeeperException.NoNodeException) { if (!quiet) { Log.Error("No node in path [" + nodePath + "]"); } } catch (Exception ex) { throw new IOException(ex); } return(null); }
private void ReadFromDisk(System.IO.IsolatedStorage.IsolatedStorageFile iso, string storeFile) { DataInputStream dis = FileUtils.ReadIsolatedStorageFileToDataInput(iso, storeFile); try { string header = dis.ReadUTF(); if (!header.Equals(HEADER)) { throw new RecordStoreException("Store file header mismatch: " + header); } nextRecordId = dis.ReadInt(); int size = dis.ReadInt(); records.Clear(); for (int i = 0; i < size; i++) { long pSize = dis.ReadLong(); int pId = dis.ReadInt(); byte[] buffer = new byte[pSize]; dis.Read(buffer); RecordItem ri = new RecordItem(pId, buffer); records.Add(ri); } } catch (Exception e) { throw new RecordStoreException("ERROR reading store from disk (" + storeFile + "): " + e.StackTrace); } finally { if (dis != null) { dis.Close(); dis = null; } } }
/// <summary> /// Sends a packet to the remote host. /// </summary> public static INetworkPacket ReadPacket(this ConnectionState con, byte[] allData) { INetworkPacket packet; using (var memoryStream = new MemoryStream(allData)) { using (var binaryReader = new DataInputStream(memoryStream)) { long packetNumber = binaryReader.ReadLong(); binaryReader.Flush(); System.Diagnostics.Debug.WriteLine($"Read packet with ID: {packetNumber}"); Debug.WriteLine("Getting new packet by id!"); packet = DeckServiceProvider.GetNewNetworkPacketById(packetNumber); Debug.WriteLine($"Getting new packet by id [{packet.GetType().Name}] - Success!"); Debug.WriteLine($"Getting data from stream [ID:{packetNumber}]!"); packet.FromInputStream(binaryReader); Debug.WriteLine($"Getting data from stream[ID:{packetNumber}] - Success!"); packet.Execute(con); } } if (!packet.CanServerReceive()) { // throw new Exception($"Server can't receive NetworkPacket[ID: {packet.GetPacketNumber()}]."); } return(packet); }
/// <exception cref="System.IO.IOException"/> private void ProcessFileDiff(DataInputStream @in, ImageVisitor v, string currentINodeName ) { int snapshotId = @in.ReadInt(); v.VisitEnclosingElement(ImageVisitor.ImageElement.SnapshotFileDiff, ImageVisitor.ImageElement .SnapshotDiffSnapshotid, snapshotId); v.Visit(ImageVisitor.ImageElement.SnapshotFileSize, @in.ReadLong()); if (@in.ReadBoolean()) { v.VisitEnclosingElement(ImageVisitor.ImageElement.SnapshotInodeFileAttributes); if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.OptimizeSnapshotInodes, imageVersion)) { ProcessINodeFileAttributes(@in, v, currentINodeName); } else { ProcessINode(@in, v, true, currentINodeName, true); } v.LeaveEnclosingElement(); } v.LeaveEnclosingElement(); }
/// <summary>Process directories when snapshot is supported.</summary> /// <exception cref="System.IO.IOException"/> private void ProcessDirectoryWithSnapshot(DataInputStream @in, ImageVisitor v, bool skipBlocks) { // 1. load dir node id long inodeId = @in.ReadLong(); string dirName = Sharpen.Collections.Remove(dirNodeMap, inodeId); bool visitedRef = subtreeMap[inodeId]; if (visitedRef != null) { if (visitedRef) { // the subtree has been visited return; } else { // first time to visit subtreeMap[inodeId] = true; } } // else the dir is not linked by a RefNode, thus cannot be revisited // 2. load possible snapshots ProcessSnapshots(@in, v, dirName); // 3. load children nodes ProcessChildren(@in, v, skipBlocks, dirName); // 4. load possible directory diff list ProcessDirectoryDiffList(@in, v, dirName); // recursively process sub-directories int numSubTree = @in.ReadInt(); for (int i = 0; i < numSubTree; i++) { ProcessDirectoryWithSnapshot(@in, v, skipBlocks); } }
/// <exception cref="IOException"/> public ConstantPool(DataInputStream @in) { int size = @in.ReadUnsignedShort(); pool = new List <PooledConstant>(size); BitSet[] nextPass = new BitSet[] { new BitSet(size), new BitSet(size), new BitSet (size) }; // first dummy constant pool.Add(null); // first pass: read the elements for (int i = 1; i < size; i++) { byte tag = unchecked ((byte)@in.ReadUnsignedByte()); switch (tag) { case ICodeConstants.CONSTANT_Utf8: { pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Utf8, @in.ReadUTF())); break; } case ICodeConstants.CONSTANT_Integer: { pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Integer, (@in.ReadInt ()))); break; } case ICodeConstants.CONSTANT_Float: { pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Float, @in.ReadFloat())); break; } case ICodeConstants.CONSTANT_Long: { pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Long, @in.ReadLong())); pool.Add(null); i++; break; } case ICodeConstants.CONSTANT_Double: { pool.Add(new PrimitiveConstant(ICodeConstants.CONSTANT_Double, @in.ReadDouble())); pool.Add(null); i++; break; } case ICodeConstants.CONSTANT_Class: case ICodeConstants.CONSTANT_String: case ICodeConstants.CONSTANT_MethodType: { pool.Add(new PrimitiveConstant(tag, @in.ReadUnsignedShort())); nextPass[0].Set(i); break; } case ICodeConstants.CONSTANT_NameAndType: { pool.Add(new LinkConstant(tag, @in.ReadUnsignedShort(), @in.ReadUnsignedShort())); nextPass[0].Set(i); break; } case ICodeConstants.CONSTANT_Fieldref: case ICodeConstants.CONSTANT_Methodref: case ICodeConstants.CONSTANT_InterfaceMethodref: case ICodeConstants.CONSTANT_InvokeDynamic: { pool.Add(new LinkConstant(tag, @in.ReadUnsignedShort(), @in.ReadUnsignedShort())); nextPass[1].Set(i); break; } case ICodeConstants.CONSTANT_MethodHandle: { pool.Add(new LinkConstant(tag, @in.ReadUnsignedByte(), @in.ReadUnsignedShort())); nextPass[2].Set(i); break; } } } // resolving complex pool elements foreach (BitSet pass in nextPass) { int idx = 0; while ((idx = pass.NextSetBit(idx + 1)) > 0) { pool[idx].ResolveConstant(this); } } // get global constant pool interceptor instance, if any available interceptor = DecompilerContext.GetPoolInterceptor(); }
/* (non-Javadoc) * @see ImageLoader#processImage(java.io.DataInputStream, ImageVisitor, boolean) */ /// <exception cref="System.IO.IOException"/> public override void LoadImage(DataInputStream @in, ImageVisitor v, bool skipBlocks ) { bool done = false; try { v.Start(); v.VisitEnclosingElement(ImageVisitor.ImageElement.FsImage); imageVersion = @in.ReadInt(); if (!CanLoadVersion(imageVersion)) { throw new IOException("Cannot process fslayout version " + imageVersion); } if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddLayoutFlags, imageVersion )) { LayoutFlags.Read(@in); } v.Visit(ImageVisitor.ImageElement.ImageVersion, imageVersion); v.Visit(ImageVisitor.ImageElement.NamespaceId, @in.ReadInt()); long numInodes = @in.ReadLong(); v.Visit(ImageVisitor.ImageElement.GenerationStamp, @in.ReadLong()); if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.SequentialBlockId, imageVersion )) { v.Visit(ImageVisitor.ImageElement.GenerationStampV2, @in.ReadLong()); v.Visit(ImageVisitor.ImageElement.GenerationStampV1Limit, @in.ReadLong()); v.Visit(ImageVisitor.ImageElement.LastAllocatedBlockId, @in.ReadLong()); } if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.StoredTxids, imageVersion )) { v.Visit(ImageVisitor.ImageElement.TransactionId, @in.ReadLong()); } if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddInodeId, imageVersion )) { v.Visit(ImageVisitor.ImageElement.LastInodeId, @in.ReadLong()); } bool supportSnapshot = NameNodeLayoutVersion.Supports(LayoutVersion.Feature.Snapshot , imageVersion); if (supportSnapshot) { v.Visit(ImageVisitor.ImageElement.SnapshotCounter, @in.ReadInt()); int numSnapshots = @in.ReadInt(); v.Visit(ImageVisitor.ImageElement.NumSnapshotsTotal, numSnapshots); for (int i = 0; i < numSnapshots; i++) { ProcessSnapshot(@in, v); } } if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.FsimageCompression, imageVersion )) { bool isCompressed = @in.ReadBoolean(); v.Visit(ImageVisitor.ImageElement.IsCompressed, isCompressed.ToString()); if (isCompressed) { string codecClassName = Text.ReadString(@in); v.Visit(ImageVisitor.ImageElement.CompressCodec, codecClassName); CompressionCodecFactory codecFac = new CompressionCodecFactory(new Configuration( )); CompressionCodec codec = codecFac.GetCodecByClassName(codecClassName); if (codec == null) { throw new IOException("Image compression codec not supported: " + codecClassName); } @in = new DataInputStream(codec.CreateInputStream(@in)); } } ProcessINodes(@in, v, numInodes, skipBlocks, supportSnapshot); subtreeMap.Clear(); dirNodeMap.Clear(); ProcessINodesUC(@in, v, skipBlocks); if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.DelegationToken, imageVersion )) { ProcessDelegationTokens(@in, v); } if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.Caching, imageVersion)) { ProcessCacheManagerState(@in, v); } v.LeaveEnclosingElement(); // FSImage done = true; } finally { if (done) { v.Finish(); } else { v.FinishAbnormally(); } } }
/// <summary>Process an INode</summary> /// <param name="in">image stream</param> /// <param name="v">visitor</param> /// <param name="skipBlocks">skip blocks or not</param> /// <param name="parentName">the name of its parent node</param> /// <param name="isSnapshotCopy">whether or not the inode is a snapshot copy</param> /// <exception cref="System.IO.IOException"/> private void ProcessINode(DataInputStream @in, ImageVisitor v, bool skipBlocks, string parentName, bool isSnapshotCopy) { bool supportSnapshot = NameNodeLayoutVersion.Supports(LayoutVersion.Feature.Snapshot , imageVersion); bool supportInodeId = NameNodeLayoutVersion.Supports(LayoutVersion.Feature.AddInodeId , imageVersion); v.VisitEnclosingElement(ImageVisitor.ImageElement.Inode); string pathName = ReadINodePath(@in, parentName); v.Visit(ImageVisitor.ImageElement.InodePath, pathName); long inodeId = INodeId.GrandfatherInodeId; if (supportInodeId) { inodeId = @in.ReadLong(); v.Visit(ImageVisitor.ImageElement.InodeId, inodeId); } v.Visit(ImageVisitor.ImageElement.Replication, @in.ReadShort()); v.Visit(ImageVisitor.ImageElement.ModificationTime, FormatDate(@in.ReadLong())); if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.FileAccessTime, imageVersion )) { v.Visit(ImageVisitor.ImageElement.AccessTime, FormatDate(@in.ReadLong())); } v.Visit(ImageVisitor.ImageElement.BlockSize, @in.ReadLong()); int numBlocks = @in.ReadInt(); ProcessBlocks(@in, v, numBlocks, skipBlocks); if (numBlocks >= 0) { // File if (supportSnapshot) { // make sure subtreeMap only contains entry for directory Sharpen.Collections.Remove(subtreeMap, inodeId); // process file diffs ProcessFileDiffList(@in, v, parentName); if (isSnapshotCopy) { bool underConstruction = @in.ReadBoolean(); if (underConstruction) { v.Visit(ImageVisitor.ImageElement.ClientName, FSImageSerialization.ReadString(@in )); v.Visit(ImageVisitor.ImageElement.ClientMachine, FSImageSerialization.ReadString( @in)); } } } ProcessPermission(@in, v); } else { if (numBlocks == -1) { // Directory if (supportSnapshot && supportInodeId) { dirNodeMap[inodeId] = pathName; } v.Visit(ImageVisitor.ImageElement.NsQuota, numBlocks == -1 ? @in.ReadLong() : -1); if (NameNodeLayoutVersion.Supports(LayoutVersion.Feature.DiskspaceQuota, imageVersion )) { v.Visit(ImageVisitor.ImageElement.DsQuota, numBlocks == -1 ? @in.ReadLong() : -1); } if (supportSnapshot) { bool snapshottable = @in.ReadBoolean(); if (!snapshottable) { bool withSnapshot = @in.ReadBoolean(); v.Visit(ImageVisitor.ImageElement.IsWithsnapshotDir, bool.ToString(withSnapshot)); } else { v.Visit(ImageVisitor.ImageElement.IsSnapshottableDir, bool.ToString(snapshottable )); } } ProcessPermission(@in, v); } else { if (numBlocks == -2) { v.Visit(ImageVisitor.ImageElement.Symlink, Text.ReadString(@in)); ProcessPermission(@in, v); } else { if (numBlocks == -3) { // reference node bool isWithName = @in.ReadBoolean(); int snapshotId = @in.ReadInt(); if (isWithName) { v.Visit(ImageVisitor.ImageElement.SnapshotLastSnapshotId, snapshotId); } else { v.Visit(ImageVisitor.ImageElement.SnapshotDstSnapshotId, snapshotId); } bool firstReferred = @in.ReadBoolean(); if (firstReferred) { // if a subtree is linked by multiple "parents", the corresponding dir // must be referred by a reference node. we put the reference node into // the subtreeMap here and let its value be false. when we later visit // the subtree for the first time, we change the value to true. subtreeMap[inodeId] = false; v.VisitEnclosingElement(ImageVisitor.ImageElement.SnapshotRefInode); ProcessINode(@in, v, skipBlocks, parentName, isSnapshotCopy); v.LeaveEnclosingElement(); } else { // referred inode v.Visit(ImageVisitor.ImageElement.SnapshotRefInodeId, @in.ReadLong()); } } } } } v.LeaveEnclosingElement(); }