public static StreamName Parse(string str) { var result = new StreamName(); var param_begin = str.IndexOf('?'); if (param_begin<0) { result.Name = str; return result; } result.Name = Uri.UnescapeDataString(str.Substring(0, param_begin)); var params_str = str.Substring(param_begin+1); foreach (var param_str in params_str.Split('&')) { var idx = param_str.IndexOf('='); if (idx<0) continue; var key = Uri.UnescapeDataString(param_str.Substring(0, idx)); var val = Uri.UnescapeDataString(param_str.Substring(idx+1)); result.Parameters[key] = val; } return result; }
public void test1() { StreamName s1 = new StreamName(3, OrcProto.Stream.Types.Kind.DATA); StreamName s2 = new StreamName(3, OrcProto.Stream.Types.Kind.DICTIONARY_DATA); StreamName s3 = new StreamName(5, OrcProto.Stream.Types.Kind.DATA); StreamName s4 = new StreamName(5, OrcProto.Stream.Types.Kind.DICTIONARY_DATA); StreamName s1p = new StreamName(3, OrcProto.Stream.Types.Kind.DATA); Assert.Equal(true, s1.Equals(s1)); Assert.Equal(false, s1.Equals(s2)); Assert.Equal(false, s1.Equals(s3)); Assert.Equal(true, s1.Equals(s1p)); Assert.Equal(true, s1.CompareTo(null) < 0); Assert.Equal(false, s1.Equals(null)); Assert.Equal(true, s1.CompareTo(s2) < 0); Assert.Equal(true, s2.CompareTo(s3) < 0); Assert.Equal(true, s3.CompareTo(s4) < 0); Assert.Equal(true, s4.CompareTo(s1p) > 0); Assert.Equal(0, s1p.CompareTo(s1)); }
public static StreamName Parse(string str) { var result = new StreamName(); var match = namePattern.Match(str); if (!match.Success) { result.Name = str; return result; } result.Name = Uri.UnescapeDataString(match.Groups["name"].Value); if (match.Groups["format"].Success) { result.Format = Uri.UnescapeDataString(match.Groups["format"].Value); } if (match.Groups["params"].Success) { var params_str = match.Groups["params"].Value; foreach (var param_str in params_str.Split('&')) { var idx = param_str.IndexOf('='); if (idx<0) continue; var key = Uri.UnescapeDataString(param_str.Substring(0, idx)); var val = Uri.UnescapeDataString(param_str.Substring(idx+1)); result.Parameters[key] = val; } } return result; }
private async Task<Channel> RequestChannel( StreamName stream_name, CancellationToken cancel_token) { Guid channel_id; if (!Guid.TryParse(stream_name.Name, out channel_id)) { return null; } var tracker_uri = stream_name.Parameters.ContainsKey("tip") ? OutputStreamBase.CreateTrackerUri(channel_id, stream_name.Parameters["tip"]) : null; var channel = owner.RequestChannel(channel_id, tracker_uri); if (channel==null) return null; var trying = 0; while ( trying++<10 && (channel.ChannelInfo==null || String.IsNullOrEmpty(channel.ChannelInfo.ContentType))){ await Task.Delay(1000, cancel_token); } if (channel.ChannelInfo==null || String.IsNullOrEmpty(channel.ChannelInfo.ContentType) || channel.ChannelInfo.ContentType!="FLV") { return null; } return channel; }
public static IList<Win32StreamInfo> ListStreams(string filePath) { if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException("filePath"); if (-1 != filePath.IndexOfAny(Path.GetInvalidPathChars())) throw new ArgumentException(Resources.Error_InvalidFileChars, "filePath"); var result = new List<Win32StreamInfo>(); using (SafeFileHandle hFile = SafeCreateFile(filePath, NativeFileAccess.GenericRead, FileShare.Read, IntPtr.Zero, FileMode.Open, NativeFileFlags.BackupSemantics, IntPtr.Zero)) using (var hName = new StreamName()) { if (!hFile.IsInvalid) { var streamId = new Win32StreamId(); int dwStreamHeaderSize = Marshal.SizeOf(streamId); bool finished = false; IntPtr context = IntPtr.Zero; int bytesRead; string name; try { while (!finished) { // Read the next stream header: if (!BackupRead(hFile, ref streamId, dwStreamHeaderSize, out bytesRead, false, false, ref context)) { finished = true; } else if (dwStreamHeaderSize != bytesRead) { finished = true; } else { // Read the stream name: if (0 >= streamId.StreamNameSize) { name = null; } else { hName.EnsureCapacity(streamId.StreamNameSize); if (!BackupRead(hFile, hName.MemoryBlock, streamId.StreamNameSize, out bytesRead, false, false, ref context)) { name = null; finished = true; } else { // Unicode chars are 2 bytes: name = hName.ReadStreamName(bytesRead >> 1); } } // Add the stream info to the result: if (!string.IsNullOrEmpty(name)) { result.Add(new Win32StreamInfo { StreamType = (FileStreamType)streamId.StreamId, StreamAttributes = (FileStreamAttributes)streamId.StreamAttributes, StreamSize = streamId.Size.ToInt64(), StreamName = name }); } // Skip the contents of the stream: int bytesSeekedLow, bytesSeekedHigh; if (!finished && !BackupSeek(hFile, streamId.Size.Low, streamId.Size.High, out bytesSeekedLow, out bytesSeekedHigh, ref context)) { finished = true; } } } } finally { // Abort the backup: BackupRead(hFile, hName.MemoryBlock, 0, out bytesRead, true, false, ref context); } } } return result; }
/** * Create a stream to store part of a column. * @param column the column id for the stream * @param kind the kind of stream * @return The output outStream that the section needs to be written to. * @ */ public OutStream createStream(int column, OrcProto.Stream.Types.Kind kind) { StreamName name = new StreamName(column, kind); CompressionModifier[] modifiers; switch (kind) { case OrcProto.Stream.Types.Kind.BLOOM_FILTER: case OrcProto.Stream.Types.Kind.DATA: case OrcProto.Stream.Types.Kind.DICTIONARY_DATA: if (getCompressionStrategy() == OrcFile.CompressionStrategy.SPEED) { modifiers = new[] { CompressionModifier.FAST, CompressionModifier.TEXT }; } else { modifiers = new[] { CompressionModifier.DEFAULT, CompressionModifier.TEXT }; } break; case OrcProto.Stream.Types.Kind.LENGTH: case OrcProto.Stream.Types.Kind.DICTIONARY_COUNT: case OrcProto.Stream.Types.Kind.PRESENT: case OrcProto.Stream.Types.Kind.ROW_INDEX: case OrcProto.Stream.Types.Kind.SECONDARY: // easily compressed using the fastest modes modifiers = new[] { CompressionModifier.FASTEST, CompressionModifier.BINARY }; break; default: LOG.warn("Missing ORC compression modifiers for " + kind); modifiers = null; break; } BufferedStream result = writer.streams.get(name); if (result == null) { result = new BufferedStream(name.ToString(), writer.bufferSize, writer.codec == null ? writer.codec : writer.codec.modify(modifiers)); writer.streams.Add(name, result); } return result.outStream; }