private static (char, char) RequestOption(string text) { text.ForEach(letter => { Sleep(60); WriteValue(letter); }); var files = new[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }; var ranks = new[] { '1', '2', '3', '4', '5', '6', '7', '8' }; var file = ReadOption(files.Contains, "Insert between a and h")(); var rank = ReadOption(ranks.Contains, "Insert between 8 and 1")(); return(file, rank); Func <char> ReadOption(Func <char, bool> condition, string invalidMessage) => () => { bool valid; char option; do { option = ReadChar(); valid = condition(option); if (!valid) { WriteError(invalidMessage); } }while (!valid); return(option); }; }
public override int Read(Span <byte> destination, long offset, ReadOption options) { long inPos = offset; int outPos = 0; int remaining = ValidateReadParamsAndGetSize(destination, offset); while (remaining > 0) { int fileIndex = GetSubFileIndexFromOffset(offset); IFile file = Sources[fileIndex]; long fileOffset = offset - fileIndex * SubFileSize; long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, GetSize()); int bytesToRead = (int)Math.Min(fileEndOffset - inPos, remaining); int bytesRead = file.Read(destination.Slice(outPos, bytesToRead), fileOffset, options); outPos += bytesRead; inPos += bytesRead; remaining -= bytesRead; if (bytesRead < bytesToRead) { break; } } return(outPos); }
public override int Read(Span <byte> destination, long offset, ReadOption options) { #if STREAM_SPAN lock (Locker) { if (BaseStream.Position != offset) { BaseStream.Position = offset; } return(BaseStream.Read(destination)); } #else byte[] buffer = ArrayPool <byte> .Shared.Rent(destination.Length); try { int bytesRead; lock (Locker) { if (BaseStream.Position != offset) { BaseStream.Position = offset; } bytesRead = BaseStream.Read(buffer, 0, destination.Length); } new Span <byte>(buffer, 0, destination.Length).CopyTo(destination); return(bytesRead); } finally { ArrayPool <byte> .Shared.Return(buffer); } #endif }
/// <summary> /// Creates an instance of <see cref="ExcelBinaryReader"/> /// </summary> /// <param name="fileStream">The file stream.</param> /// <returns></returns> public static IExcelDataReader CreateBinaryReader(Stream fileStream, ReadOption option) { IExcelDataReader reader = new ExcelBinaryReader(option); reader.Initialize(fileStream); return reader; }
// Read(u32 readOption, u64 offset, u64 size) -> (u64 out_size, buffer<u8, 0x46, 0> out_buf) public ResultCode Read(ServiceCtx context) { long position = context.Request.ReceiveBuff[0].Position; ReadOption readOption = (ReadOption)context.RequestData.ReadInt32(); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = new byte[size]; int readSize; try { readSize = _baseFile.Read(data, offset, readOption); } catch (HorizonResultException ex) { return((ResultCode)ex.ResultValue.Value); } context.Memory.WriteBytes(position, data); context.ResponseData.Write((long)readSize); return(ResultCode.Success); }
/// <summary> /// Creates an instance of <see cref="ExcelBinaryReader"/> /// </summary> /// <param name="fileStream">The file stream.</param> /// <returns></returns> public static IExcelDataReader CreateBinaryReader(Stream fileStream, bool convertOADate, ReadOption readOption) { IExcelDataReader reader = CreateBinaryReader(fileStream, readOption); ((ExcelBinaryReader)reader).ConvertOaDate = convertOADate; return reader; }
public static IExcelDataReader CreateBinaryReader(Stream fileStream, ReadOption option) { IExcelDataReader reader = new ExcelBinaryReader(option); reader.Initialize(fileStream); return(reader); }
public override int Read(Span <byte> destination, long offset, ReadOption options) { int toRead = ValidateReadParamsAndGetSize(destination, offset); BaseStorage.Read(destination.Slice(0, toRead), offset); return(toRead); }
/// <summary> /// Creates an instance of <see cref="ExcelBinaryReader"/> /// </summary> /// <param name="fileStream">The file stream.</param> /// <returns></returns> public static IExcelDataReader CreateBinaryReader(Stream fileStream, ReadOption option) { var factory = CreateFactory(); var portableReadOption = (ExcelDataReader.Portable.ReadOption)option; var reader = AsyncHelper.RunSync(() => factory.CreateBinaryReaderAsync(fileStream, portableReadOption)); return(new ExcelBinaryReader(reader)); }
/// <summary> /// Returns full apdu command to read binary data form iClass card. /// </summary> /// <param name="option"> Read binary pcsc command parametr.</param> /// <param name="blockNumber"></param> /// <param name="expectedLength"></param> /// <param name="bookNumber"> Used only if option set to <see cref="ReadOption.WithSelect"/></param> /// <param name="pageNumber"> Used only if option set to <see cref="ReadOption.WithSelect"/></param> /// <returns></returns> public string GetiClassReadApdu(ReadOption option, byte blockNumber, byte expectedLength, BookNumber bookNumber = BookNumber.Book0, PageNumber pageNumber = PageNumber.Page0) { if (option != ReadOption.WithSelect) { return("FFB0" + ((byte)option).ToString("X2") + blockNumber.ToString("X2") + expectedLength.ToString("X2")); } byte address = 0x00; address |= (byte)option; address |= bookNumber != BookNumber.Book0 ? (byte)(1 << 3) : (byte)0; address |= (byte)pageNumber; return("FFB0" + address.ToString("X2") + blockNumber.ToString("X2") + expectedLength.ToString("X2")); }
public T Read(string path) { try { var bytes = File.ReadAllBytes(path); return(Parser.Parse(bytes)); } catch (Exception e) { if (!ReadOption.HasFlag(FileReadOption.EmptyIfFailure)) { // エラーにするなら素通し throw; } ChipstarLog.Log_CatchException(e); return(new T()); } }
public int ReadFile(FileHandle handle, Span <byte> destination, long offset, ReadOption option) { int bytesRead; if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); bytesRead = handle.File.Read(destination, offset, option); TimeSpan endTime = Time.GetCurrent(); OutputAccessLog(startTime, endTime, handle, $", offset: {offset}, size: {destination.Length}"); } else { bytesRead = handle.File.Read(destination, offset, option); } return(bytesRead); }
// Read(u32 readOption, u64 offset, u64 size) -> (u64 out_size, buffer<u8, 0x46, 0> out_buf) public ResultCode Read(ServiceCtx context) { long position = context.Request.ReceiveBuff[0].Position; ReadOption readOption = new ReadOption(context.RequestData.ReadInt32()); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = new byte[size]; Result result = _baseFile.Read(out long bytesRead, offset, data, readOption); context.Memory.Write((ulong)position, data); context.ResponseData.Write(bytesRead); return (ResultCode)result.Value; }
// Read(u32 readOption, u64 offset, u64 size) -> (u64 out_size, buffer<u8, 0x46, 0> out_buf) public ResultCode Read(ServiceCtx context) { ulong position = context.Request.ReceiveBuff[0].Position; ReadOption readOption = context.RequestData.ReadStruct <ReadOption>(); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = new byte[context.Request.ReceiveBuff[0].Size]; Result result = _baseFile.Get.Read(out long bytesRead, offset, new OutBuffer(data), size, readOption); context.Memory.Write(position, data); context.ResponseData.Write(bytesRead); return((ResultCode)result.Value); }
// Read(u32 readOption, u64 offset, u64 size) -> (u64 out_size, buffer<u8, 0x46, 0> out_buf) public long Read(ServiceCtx context) { long position = context.Request.ReceiveBuff[0].Position; ReadOption readOption = (ReadOption)context.RequestData.ReadInt32(); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = new byte[size]; int readSize = _baseFile.Read(data, offset, readOption); context.Memory.WriteBytes(position, data); context.ResponseData.Write((long)readSize); return(0); }
public int U_Read(Array buff, int offset, int size, ReadOption option = ReadOption.ReadWhenSizeAvailable) { if (option == ReadOption.ReadWhenSizeAvailable) { if (_queue.Size < size) { return(0); } else { _queue.dequeueTo(buff, offset, size); return(size); } } else { int realSize = (_queue.Size > size) ? size : _queue.Size; _queue.dequeueTo(buff, offset, realSize); return(realSize); } }
public Result Read(out long bytesRead, long offset, Span <byte> destination, ReadOption option) { const int maxTryCount = 2; UnsafeHelpers.SkipParamInit(out bytesRead); if (offset < 0) { return(ResultFs.InvalidOffset.Log()); } if (destination.Length < 0) { return(ResultFs.InvalidSize.Log()); } Result rc = Result.Success; long tmpBytesRead = 0; for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { rc = BaseFile.Read(out tmpBytesRead, offset, destination, option); // Retry on ResultDataCorrupted if (!ResultFs.DataCorrupted.Includes(rc)) { break; } } if (rc.IsFailure()) { return(rc); } bytesRead = tmpBytesRead; return(Result.Success); }
protected override Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { bytesRead = 0; Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode); if (rc.IsFailure()) { return(rc); } return(File.Read(out bytesRead, offset, destination.Slice(0, (int)toRead), options)); }
public static extern Result Read(FileHandle handle, long offset, byte[] buffer, long size); // 0x00A15900-0x00A15930 public static extern Result Read(ref long outValue, FileHandle handle, long offset, byte[] buffer, long size, ReadOption option); // 0x00A15930-0x00A15960
/// <summary> /// Creates an instance of <see cref="ExcelBinaryReader"/> /// </summary> /// <param name="fileStream">The file stream.</param> /// <param name="convertOADate"></param> /// <param name="readOption"></param> /// <returns></returns> public static IExcelDataReader CreateBinaryReader(Stream fileStream, bool convertOADate, ReadOption readOption) { var reader = new ExcelBinaryReader(); reader.ConvertOaDate = convertOADate; reader.ReadOption = readOption; reader.Initialize(fileStream); return(reader); }
protected override Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { bytesRead = default; Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode); if (rc.IsFailure()) { return(rc); } if (toRead == 0) { bytesRead = 0; return(Result.Success); } rc = BaseStorage.Read(offset, destination.Slice(0, (int)toRead)); if (rc.IsFailure()) { return(rc); } bytesRead = toRead; return(Result.Success); }
public static extern nn.Result Read( ref long outValue, FileHandle handle, long offset, byte[] buffer, long size, ReadOption option);
public int Read(Span <byte> destination, long offset, ReadOption options) { CheckIfDisposed(); return(File.Read(destination, offset, options)); }
public abstract int Read(Span <byte> destination, long offset, ReadOption options);
protected override Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { bytesRead = default; Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode); if (rc.IsFailure()) { return(rc); } #if STREAM_SPAN lock (Locker) { if (BaseStream.Position != offset) { BaseStream.Position = offset; } bytesRead = BaseStream.Read(destination.Slice(0, (int)toRead)); return(Result.Success); } #else byte[] buffer = ArrayPool <byte> .Shared.Rent((int)toRead); try { lock (Locker) { if (BaseStream.Position != offset) { BaseStream.Position = offset; } bytesRead = BaseStream.Read(buffer, 0, (int)toRead); } new Span <byte>(buffer, 0, (int)bytesRead).CopyTo(destination); return(Result.Success); } finally { ArrayPool <byte> .Shared.Return(buffer); } #endif }
internal ExcelBinaryReader(ReadOption readOption) : this() { m_ReadOption = readOption; }
protected override Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { bytesRead = default; Result rc = ValidateReadParams(out long bytesToRead, offset, destination.Length, Mode); if (rc.IsFailure()) { return(rc); } bool hashNeeded = false; long fileStorageOffset = ParentFs.DataOffset + _entry.Offset; if (typeof(T) == typeof(HashedEntry)) { ref HashedEntry entry = ref Unsafe.As <T, HashedEntry>(ref _entry); long readEnd = offset + destination.Length; long hashEnd = entry.HashOffset + entry.HashSize; // The hash must be checked if any part of the hashed region is read hashNeeded = entry.HashOffset < readEnd && hashEnd >= offset; }
protected override Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { bytesRead = default; long inPos = offset; int outPos = 0; Result rc = ValidateReadParams(out long remaining, offset, destination.Length, Mode); if (rc.IsFailure()) { return(rc); } GetSize(out long fileSize).ThrowIfFailure(); while (remaining > 0) { int fileIndex = GetSubFileIndexFromOffset(offset); IFile file = Sources[fileIndex]; long fileOffset = offset - fileIndex * SubFileSize; long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, fileSize); int bytesToRead = (int)Math.Min(fileEndOffset - inPos, remaining); rc = file.Read(out long subFileBytesRead, fileOffset, destination.Slice(outPos, bytesToRead), options); if (rc.IsFailure()) { return(rc); } outPos += (int)subFileBytesRead; inPos += subFileBytesRead; remaining -= subFileBytesRead; if (bytesRead < bytesToRead) { break; } } bytesRead = outPos; return(Result.Success); }
public static IExcelDataReader CreateBinaryReader(Stream fileStream, bool convertOADate, ReadOption readOption) { IExcelDataReader reader = CreateBinaryReader(fileStream, readOption); ((ExcelBinaryReader)reader).ConvertOaDate = convertOADate; return(reader); }
// Methods public static extern Result Read(FileHandle handle, long offset, byte[] buffer, long size, ReadOption option); // 0x00A158D0-0x00A15900
protected override Result ReadImpl(out long bytesRead, long offset, Span <byte> destination, ReadOption options) { return(BaseFile.Read(out bytesRead, offset, destination, options)); }
public override int Read(Span <byte> destination, long offset, ReadOption options) { return(BaseFile.Read(destination, offset, options)); }