/// <summary> /// Returns a stream that can be used to access the contents of the object, if the object is not a folder. /// </summary> /// <returns>A stream that can be used to access the object contents.</returns> public override ISharedStreamReader GetStream() { ISharedStreamReader baseStream = base.GetStream(); if (baseStream != null) { // file is cached Trace.TraceInformation("Reading from local cache {0}", baseStream); return(baseStream); } Stream stream; if (this.IsDfsStream) { var dfsFileStream = this.client.GetDfsFileStream(this.path); stream = dfsFileStream.Stream; } else { stream = new AzureLogReaderStream( this.client.AccountName, this.client.AccountKey, this.client.ContainerName, this.path); } long size = this.Size; int bufferSize = 1024 * 1024; if (size >= 0) { bufferSize = (int)(size / 10); if (bufferSize < 1024 * 1024) { bufferSize = 1024 * 1024; } if (bufferSize > 20 * 1024 * 1024) { bufferSize = 20 * 1024 * 1024; } } StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8, false, bufferSize); if (this.ShouldCacheLocally && this.LocalCachePath != null) { // cache it if (this.RepresentsAFolder) { throw new ClusterException("Cannot cache folders"); } StreamWriter writer = this.CreateTempStream(); return(new SharedStreamReader(reader, writer, this.OnClose)); } else { // dont cache it return(new SharedStreamReader(reader)); } }
static void Main(string[] args) { Uri uri = new Uri(args[0]); string account, key, container, blob; Utils.FromAzureUri(uri, out account, out key, out container, out blob); if (key == null) { AzureSubscriptions subs = new AzureSubscriptions(); key = subs.GetAccountKeyAsync(account).Result; uri = Utils.ToAzureUri(account, container, blob, null, key); } Stream log = new AzureLogReaderStream(uri); if (args.Length > 1 && args[1] == "-tail") { Tail(log); } else { log.CopyTo(Console.OpenStandardOutput()); } }
/// <summary> /// Returns a stream that can be used to access the contents of the object, if the object is not a folder. /// </summary> /// <returns>A stream that can be used to access the object contents.</returns> public override ISharedStreamReader GetStream() { ISharedStreamReader baseStream = base.GetStream(); if (baseStream != null) { // file is cached Trace.TraceInformation("Reading from local cache {0}", baseStream); return baseStream; } Stream stream; if (this.IsDfsStream) { var dfsFileStream = this.client.GetDfsFileStream(this.path); stream = dfsFileStream.Stream; } else { stream = new AzureLogReaderStream( this.client.AccountName, this.client.AccountKey, this.client.ContainerName, this.path); } long size = this.Size; int bufferSize = 1024*1024; if (size >= 0) { bufferSize = (int)(size/10); if (bufferSize < 1024*1024) bufferSize = 1024*1024; if (bufferSize > 20*1024*1024) bufferSize = 20*1024*1024; } StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8, false, bufferSize); if (this.ShouldCacheLocally && this.LocalCachePath != null) { // cache it if (this.RepresentsAFolder) throw new ClusterException("Cannot cache folders"); StreamWriter writer = this.CreateTempStream(); return new SharedStreamReader(reader, writer, this.OnClose); } else { // dont cache it return new SharedStreamReader(reader); } }
/// <summary> /// Returns a stream that can be used to access the contents of the object, if the object is not a folder. /// </summary> /// <returns>A stream that can be used to access the object contents.</returns> /// <param name="keepNewlines">If true keep the newlines.</param> public override ISharedStreamReader GetStream(bool keepNewlines) { ISharedStreamReader baseStream = base.GetStream(keepNewlines); if (baseStream != null) { // file is cached Trace.TraceInformation("Reading from local cache {0}", baseStream); return baseStream; } Stream stream; if (this.IsDfsStream) { Uri uri = UriFromPath(this.Config as AzureDfsClusterConfiguration, this.path); stream = this.client.GetDfsStreamReader(uri); } else { string p = AzureDfsClusterStatus.GetBlobName(this.client.ContainerName,this.path); stream = new AzureLogReaderStream( this.client.AccountName, this.client.AccountKey, this.client.ContainerName, p); } long sz = this.Size; int bufferSize = 1024*1024; if (sz >= 0) { bufferSize = (int)(sz/10); if (bufferSize < 1024*1024) bufferSize = 1024*1024; if (bufferSize > 20*1024*1024) bufferSize = 20*1024*1024; } SimpleStreamReader reader = new SimpleStreamReader(stream, true, Encoding.UTF8, false, bufferSize); if (this.ShouldCacheLocally && this.LocalCachePath != null) { // cache it if (this.RepresentsAFolder) throw new ClusterException("Cannot cache folders"); StreamWriter writer = this.CreateTempStream(); return new SharedStreamReader(reader, writer, keepNewlines, this.OnClose); } else { // dont cache it return new SharedStreamReader(reader, keepNewlines); } }