/// <exception cref="System.Exception"/> private void TestAppend() { if (!IsLocalFS()) { FileSystem fs = FileSystem.Get(GetProxiedFSConf()); fs.Mkdirs(GetProxiedFSTestDir()); Path path = new Path(GetProxiedFSTestDir(), "foo.txt"); OutputStream os = fs.Create(path); os.Write(1); os.Close(); fs.Close(); fs = GetHttpFSFileSystem(); os = fs.Append(new Path(path.ToUri().GetPath())); os.Write(2); os.Close(); fs.Close(); fs = FileSystem.Get(GetProxiedFSConf()); InputStream @is = fs.Open(path); NUnit.Framework.Assert.AreEqual(@is.Read(), 1); NUnit.Framework.Assert.AreEqual(@is.Read(), 2); NUnit.Framework.Assert.AreEqual(@is.Read(), -1); @is.Close(); fs.Close(); } }
public virtual void TestWriteAfterClose() { Configuration conf = new Configuration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build(); try { byte[] data = Sharpen.Runtime.GetBytesForString("foo"); FileSystem fs = FileSystem.Get(conf); OutputStream @out = fs.Create(new Path("/test")); @out.Write(data); @out.Close(); try { // Should fail. @out.Write(data); NUnit.Framework.Assert.Fail("Should not have been able to write more data after file is closed." ); } catch (ClosedChannelException) { } // We got the correct exception. Ignoring. // Should succeed. Double closes are OK. @out.Close(); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public override void Close() { if (@out != null) { try { if (outNeedsEnd) { outNeedsEnd = false; pckOut.End(); } @out.Close(); } catch (IOException) { } finally { // Ignore any close errors. @out = null; pckOut = null; } } if (@in != null) { try { @in.Close(); } catch (IOException) { } finally { // Ignore any close errors. @in = null; pckIn = null; } } if (myTimer != null) { try { myTimer.Terminate(); } finally { myTimer = null; timeoutIn = null; timeoutOut = null; } } }
/// <exception cref="System.Exception"/> private void TestListStatus() { FileSystem fs = FileSystem.Get(GetProxiedFSConf()); Path path = new Path(GetProxiedFSTestDir(), "foo.txt"); OutputStream os = fs.Create(path); os.Write(1); os.Close(); FileStatus status1 = fs.GetFileStatus(path); fs.Close(); fs = GetHttpFSFileSystem(); FileStatus status2 = fs.GetFileStatus(new Path(path.ToUri().GetPath())); fs.Close(); NUnit.Framework.Assert.AreEqual(status2.GetPermission(), status1.GetPermission()); NUnit.Framework.Assert.AreEqual(status2.GetPath().ToUri().GetPath(), status1.GetPath ().ToUri().GetPath()); NUnit.Framework.Assert.AreEqual(status2.GetReplication(), status1.GetReplication( )); NUnit.Framework.Assert.AreEqual(status2.GetBlockSize(), status1.GetBlockSize()); NUnit.Framework.Assert.AreEqual(status2.GetAccessTime(), status1.GetAccessTime()); NUnit.Framework.Assert.AreEqual(status2.GetModificationTime(), status1.GetModificationTime ()); NUnit.Framework.Assert.AreEqual(status2.GetOwner(), status1.GetOwner()); NUnit.Framework.Assert.AreEqual(status2.GetGroup(), status1.GetGroup()); NUnit.Framework.Assert.AreEqual(status2.GetLen(), status1.GetLen()); FileStatus[] stati = fs.ListStatus(path.GetParent()); NUnit.Framework.Assert.AreEqual(stati.Length, 1); NUnit.Framework.Assert.AreEqual(stati[0].GetPath().GetName(), path.GetName()); }
/// <exception cref="System.Exception"/> private void TestSetTimes() { if (!IsLocalFS()) { FileSystem fs = FileSystem.Get(GetProxiedFSConf()); Path path = new Path(GetProxiedFSTestDir(), "foo.txt"); OutputStream os = fs.Create(path); os.Write(1); os.Close(); FileStatus status1 = fs.GetFileStatus(path); fs.Close(); long at = status1.GetAccessTime(); long mt = status1.GetModificationTime(); fs = GetHttpFSFileSystem(); fs.SetTimes(path, mt - 10, at - 20); fs.Close(); fs = FileSystem.Get(GetProxiedFSConf()); status1 = fs.GetFileStatus(path); fs.Close(); long atNew = status1.GetAccessTime(); long mtNew = status1.GetModificationTime(); NUnit.Framework.Assert.AreEqual(mtNew, mt - 10); NUnit.Framework.Assert.AreEqual(atNew, at - 20); } }
public virtual void Close() { try { if (@in != null && !in_dontclose) { @in.Close(); } @in = null; } catch (Exception) { } Out_close(); try { if (out_ext != null && !out_ext_dontclose) { out_ext.Close(); } out_ext = null; } catch (Exception) { } }
/// <exception cref="System.Exception"/> public virtual void TestWriteConf() { Configuration conf = new HdfsConfiguration(); conf.SetInt(DFSConfigKeys.DfsBlockSizeKey, 4096); System.Console.Out.WriteLine("Setting conf in: " + Runtime.IdentityHashCode(conf) ); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build(); FileSystem fs = null; OutputStream os = null; try { fs = cluster.GetFileSystem(); Path filePath = new Path("/testWriteConf.xml"); os = fs.Create(filePath); StringBuilder longString = new StringBuilder(); for (int i = 0; i < 100000; i++) { longString.Append("hello"); } // 500KB conf.Set("foobar", longString.ToString()); conf.WriteXml(os); os.Close(); os = null; fs.Close(); fs = null; } finally { IOUtils.Cleanup(null, os, fs); cluster.Shutdown(); } }
public static void SetUp() { conf = new Configuration(); conf.SetBoolean(DFSConfigKeys.DfsWebhdfsEnabledKey, true); conf.Set(DFSConfigKeys.DfsHttpPolicyKey, HttpConfig.Policy.HttpsOnly.ToString()); conf.Set(DFSConfigKeys.DfsNamenodeHttpsAddressKey, "localhost:0"); conf.Set(DFSConfigKeys.DfsDatanodeHttpsAddressKey, "localhost:0"); FilePath @base = new FilePath(Basedir); FileUtil.FullyDelete(@base); @base.Mkdirs(); keystoresDir = new FilePath(Basedir).GetAbsolutePath(); sslConfDir = KeyStoreTestUtil.GetClasspathDir(typeof(TestHttpsFileSystem)); KeyStoreTestUtil.SetupSSLConfig(keystoresDir, sslConfDir, conf, false); cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(1).Build(); cluster.WaitActive(); OutputStream os = cluster.GetFileSystem().Create(new Path("/test")); os.Write(23); os.Close(); IPEndPoint addr = cluster.GetNameNode().GetHttpsAddress(); nnAddr = NetUtils.GetHostPortString(addr); conf.Set(DFSConfigKeys.DfsNamenodeHttpsAddressKey, nnAddr); }
/// <summary> /// Generates test data of the given size according to some specific pattern /// and writes it to the provided output file. /// </summary> /// <param name="fs">FileSystem</param> /// <param name="path">Test file to be generated</param> /// <param name="size">The size of the test data to be generated in bytes</param> /// <param name="bufferLen">Pattern length</param> /// <param name="modulus">Pattern modulus</param> /// <exception cref="System.IO.IOException">thrown if an error occurs while writing the data /// </exception> public static long GenerateTestFile(FileSystem fs, Path path, long size, int bufferLen , int modulus) { byte[] testBuffer = new byte[bufferLen]; for (int i = 0; i < testBuffer.Length; ++i) { testBuffer[i] = unchecked ((byte)(i % modulus)); } OutputStream outputStream = fs.Create(path, false); long bytesWritten = 0; try { while (bytesWritten < size) { long diff = size - bytesWritten; if (diff < testBuffer.Length) { outputStream.Write(testBuffer, 0, (int)diff); bytesWritten += diff; } else { outputStream.Write(testBuffer); bytesWritten += testBuffer.Length; } } return(bytesWritten); } finally { outputStream.Close(); } }
public virtual void TestWithNoAcls() { string aclUser1 = "user:foo:rw-"; string aclUser2 = "user:bar:r--"; string aclGroup1 = "group::r--"; string aclSpec = "aclspec=user::rwx," + aclUser1 + "," + aclGroup1 + ",other::---"; string modAclSpec = "aclspec=" + aclUser2; string remAclSpec = "aclspec=" + aclUser1; string defUser1 = "default:user:glarch:r-x"; string defSpec1 = "aclspec=" + defUser1; string dir = "/noACLs"; string path = dir + "/foo"; StartMiniDFS(); CreateHttpFSServer(); FileSystem fs = FileSystem.Get(nnConf); fs.Mkdirs(new Path(dir)); OutputStream os = fs.Create(new Path(path)); os.Write(1); os.Close(); /* The normal status calls work as expected; GETACLSTATUS fails */ GetStatus(path, "GETFILESTATUS", true); GetStatus(dir, "LISTSTATUS", true); GetStatus(path, "GETACLSTATUS", false); /* All the ACL-based PUT commands fail with ACL exceptions */ PutCmd(path, "SETACL", aclSpec, false); PutCmd(path, "MODIFYACLENTRIES", modAclSpec, false); PutCmd(path, "REMOVEACLENTRIES", remAclSpec, false); PutCmd(path, "REMOVEACL", null, false); PutCmd(dir, "SETACL", defSpec1, false); PutCmd(dir, "REMOVEDEFAULTACL", null, false); miniDfs.Shutdown(); }
private static void Write(InputStream inputStream, OutputStream os, bool close = true) { var buffer = new byte[DefaultBufferSize]; try { while (inputStream.Available() > 0) { var n = inputStream.Read(buffer); if (n > 0) { os.Write(buffer, 0, n); } } if (!close) { return; } inputStream.Close(); os.Close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
/// <exception cref="System.Exception"/> private void TestContentSummary() { FileSystem fs = FileSystem.Get(GetProxiedFSConf()); Path path = new Path(GetProxiedFSTestDir(), "foo.txt"); OutputStream os = fs.Create(path); os.Write(1); os.Close(); ContentSummary hdfsContentSummary = fs.GetContentSummary(path); fs.Close(); fs = GetHttpFSFileSystem(); ContentSummary httpContentSummary = fs.GetContentSummary(path); fs.Close(); NUnit.Framework.Assert.AreEqual(httpContentSummary.GetDirectoryCount(), hdfsContentSummary .GetDirectoryCount()); NUnit.Framework.Assert.AreEqual(httpContentSummary.GetFileCount(), hdfsContentSummary .GetFileCount()); NUnit.Framework.Assert.AreEqual(httpContentSummary.GetLength(), hdfsContentSummary .GetLength()); NUnit.Framework.Assert.AreEqual(httpContentSummary.GetQuota(), hdfsContentSummary .GetQuota()); NUnit.Framework.Assert.AreEqual(httpContentSummary.GetSpaceConsumed(), hdfsContentSummary .GetSpaceConsumed()); NUnit.Framework.Assert.AreEqual(httpContentSummary.GetSpaceQuota(), hdfsContentSummary .GetSpaceQuota()); }
/// <exception cref="System.IO.IOException"></exception> protected internal override void DoDisconnect(bool hard) { try { if (Sessions != null) { foreach (var ssn in Sessions) { ssn?.Logoff(hard); } } Out?.Close(); In?.Close(); //Socket.`Close` method deleted //Socket.Close(); Socket?.Shutdown(SocketShutdown.Both); Socket?.Dispose(); } finally { Digest = null; Socket = null; TconHostName = null; } }
/// <exception cref="System.Exception"/> private void TestCreate(Path path, bool @override) { FileSystem fs = GetHttpFSFileSystem(); FsPermission permission = new FsPermission(FsAction.ReadWrite, FsAction.None, FsAction .None); OutputStream os = fs.Create(new Path(path.ToUri().GetPath()), permission, @override , 1024, (short)2, 100 * 1024 * 1024, null); os.Write(1); os.Close(); fs.Close(); fs = FileSystem.Get(GetProxiedFSConf()); FileStatus status = fs.GetFileStatus(path); if (!IsLocalFS()) { NUnit.Framework.Assert.AreEqual(status.GetReplication(), 2); NUnit.Framework.Assert.AreEqual(status.GetBlockSize(), 100 * 1024 * 1024); } NUnit.Framework.Assert.AreEqual(status.GetPermission(), permission); InputStream @is = fs.Open(path); NUnit.Framework.Assert.AreEqual(@is.Read(), 1); @is.Close(); fs.Close(); }
public void Dispose() { _mp3SoundCapture.Dispose(); if (OutputStream != null) { OutputStream.Close(); } }
/// <summary> /// /// </summary> /// <param name="pages"></param> /// <param name="destination"></param> /// <param name="cancellationSignal"></param> /// <param name="callback"></param> public override async void OnWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) { _input = null; _output = null; try { _input = new FileInputStream(FileToPrint); // if we use using on this, we get an ObjectDisposedException // TODO - investigate further _output = new FileOutputStream(destination.FileDescriptor); // if we use using on this, we get an ObjectDisposedException // TODO - investigate further byte[] buf = new byte[1024]; int bytesRead; while ((bytesRead = _input.Read(buf)) > 0) { _output.Write(buf, 0, bytesRead); } callback.OnWriteFinished(new PageRange[] { PageRange.AllPages }); } catch (Java.IO.FileNotFoundException ee) { await PrintStatusReporting.ReportExceptionSilentlyAsync(ee); } catch (Java.Lang.Exception jlex) { await PrintStatusReporting.ReportExceptionSilentlyAsync(jlex); } #pragma warning disable CA1031 // Do not catch general exception types catch (System.Exception e) { await PrintStatusReporting.ReportExceptionSilentlyAsync(e); } #pragma warning restore CA1031 // Do not catch general exception types finally { try { if (!(_input is null)) { _input.Close(); _input = null; } if (!(_output is null)) { _output.Close(); _output = null; } } #pragma warning disable CA1031 // Do not catch general exception types catch (System.Exception e) { await PrintStatusReporting.ReportExceptionSilentlyAsync(e); } #pragma warning restore CA1031 // Do not catch general exception types } }
/// <exception cref="System.IO.IOException"></exception> private void PutImpl(string bucket, string key, byte[] csum, TemporaryBuffer buf, ProgressMonitor monitor, string monitorTask) { if (monitor == null) { monitor = NullProgressMonitor.INSTANCE; } if (monitorTask == null) { monitorTask = MessageFormat.Format(JGitText.Get().progressMonUploading, key); } string md5str = Base64.EncodeBytes(csum); long len = buf.Length(); string lenstr = len.ToString(); for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++) { HttpURLConnection c = Open("PUT", bucket, key); c.SetRequestProperty("Content-Length", lenstr); c.SetRequestProperty("Content-MD5", md5str); c.SetRequestProperty(X_AMZ_ACL, acl); encryption.Request(c, X_AMZ_META); Authorize(c); c.SetDoOutput(true); c.SetFixedLengthStreamingMode((int)len); monitor.BeginTask(monitorTask, (int)(len / 1024)); OutputStream os = c.GetOutputStream(); try { buf.WriteTo(os, monitor); } finally { monitor.EndTask(); os.Close(); } switch (HttpSupport.Response(c)) { case HttpURLConnection.HTTP_OK: { return; } case HttpURLConnection.HTTP_INTERNAL_ERROR: { continue; goto default; } default: { throw Error("Writing", key, c); } } } throw MaxAttempts("Writing", key); }
/// <summary>Executes the filesystem operation.</summary> /// <param name="fs">filesystem instance to use.</param> /// <returns>void.</returns> /// <exception cref="System.IO.IOException">thrown if an IO error occured.</exception> public virtual Void Execute(FileSystem fs) { int bufferSize = fs.GetConf().GetInt("httpfs.buffer.size", 4096); OutputStream os = fs.Append(path, bufferSize); IOUtils.CopyBytes(@is, os, bufferSize, true); os.Close(); return(null); }
/// <summary>Create an empty Har archive in the FileSystem fs at the Path p.</summary> /// <param name="fs">the file system to create the Har archive in</param> /// <param name="p">the path to create the Har archive at</param> /// <exception cref="System.IO.IOException">in the event of error</exception> private static void CreateEmptyHarArchive(FileSystem fs, Path p) { fs.Mkdirs(p); OutputStream @out = fs.Create(new Path(p, "_masterindex")); @out.Write(Sharpen.Runtime.GetBytesForString(Sharpen.Extensions.ToString(HarFileSystem .Version))); @out.Close(); fs.Create(new Path(p, "_index")).Close(); }
public void ForceClose() { if (IsClosed) { return; } OutputStream.Close(); IsClosed = true; }
/// <exception cref="System.IO.IOException"/> public override void Close() { Finish(); @out.Close(); if (trackedCompressor != null) { CodecPool.ReturnCompressor(trackedCompressor); trackedCompressor = null; } }
/// <exception cref="System.IO.IOException"></exception> internal virtual void WriteTo(OutputStream os) { MessageDigest foot = Constants.NewMessageDigest(); DigestOutputStream dos = new DigestOutputStream(os, foot); bool extended = false; for (int i = 0; i < entryCnt; i++) { extended |= sortedEntries[i].IsExtended; } // Write the header. // byte[] tmp = new byte[128]; System.Array.Copy(SIG_DIRC, 0, tmp, 0, SIG_DIRC.Length); NB.EncodeInt32(tmp, 4, extended ? 3 : 2); NB.EncodeInt32(tmp, 8, entryCnt); dos.Write(tmp, 0, 12); // Write the individual file entries. // if (snapshot == null) { // Write a new index, as no entries require smudging. // for (int i_1 = 0; i_1 < entryCnt; i_1++) { sortedEntries[i_1].Write(dos); } } else { int smudge_s = (int)(snapshot.LastModified() / 1000); int smudge_ns = ((int)(snapshot.LastModified() % 1000)) * 1000000; for (int i_1 = 0; i_1 < entryCnt; i_1++) { DirCacheEntry e = sortedEntries[i_1]; if (e.MightBeRacilyClean(smudge_s, smudge_ns)) { e.SmudgeRacilyClean(); } e.Write(dos); } } if (tree != null) { TemporaryBuffer bb = new TemporaryBuffer.LocalFile(); tree.Write(tmp, bb); bb.Close(); NB.EncodeInt32(tmp, 0, EXT_TREE); NB.EncodeInt32(tmp, 4, (int)bb.Length()); dos.Write(tmp, 0, 8); bb.WriteTo(dos, null); } os.Write(foot.Digest()); os.Close(); }
/// <exception cref="System.IO.IOException"/> private static void CopyFileToStream(OutputStream @out, FilePath localfile, FileInputStream infile, DataTransferThrottler throttler, Canceler canceler) { byte[] buf = new byte[HdfsConstants.IoFileBufferSize]; try { CheckpointFaultInjector.GetInstance().AboutToSendFile(localfile); if (CheckpointFaultInjector.GetInstance().ShouldSendShortFile(localfile)) { // Test sending image shorter than localfile long len = localfile.Length(); buf = new byte[(int)Math.Min(len / 2, HdfsConstants.IoFileBufferSize)]; // This will read at most half of the image // and the rest of the image will be sent over the wire infile.Read(buf); } int num = 1; while (num > 0) { if (canceler != null && canceler.IsCancelled()) { throw new SaveNamespaceCancelledException(canceler.GetCancellationReason()); } num = infile.Read(buf); if (num <= 0) { break; } if (CheckpointFaultInjector.GetInstance().ShouldCorruptAByte(localfile)) { // Simulate a corrupted byte on the wire Log.Warn("SIMULATING A CORRUPT BYTE IN IMAGE TRANSFER!"); buf[0]++; } @out.Write(buf, 0, num); if (throttler != null) { throttler.Throttle(num, canceler); } } } catch (EofException) { Log.Info("Connection closed by client"); @out = null; } finally { // so we don't close in the finally if (@out != null) { @out.Close(); } } }
/// <summary>Atomically create or replace a single small object.</summary> /// <remarks> /// Atomically create or replace a single small object. /// <p> /// This form is only suitable for smaller contents, where the caller can /// reasonable fit the entire thing into memory. /// <p> /// End-to-end data integrity is assured by internally computing the MD5 /// checksum of the supplied data and transmitting the checksum along with /// the data itself. /// </remarks> /// <param name="bucket">name of the bucket storing the object.</param> /// <param name="key">key of the object within its bucket.</param> /// <param name="data"> /// new data content for the object. Must not be null. Zero length /// array will create a zero length object. /// </param> /// <exception cref="System.IO.IOException">creation/updating failed due to communications error. /// </exception> public virtual void Put(string bucket, string key, byte[] data) { if (encryption != WalkEncryption.NONE) { // We have to copy to produce the cipher text anyway so use // the large object code path as it supports that behavior. // OutputStream os = BeginPut(bucket, key, null, null); os.Write(data); os.Close(); return; } string md5str = Base64.EncodeBytes(NewMD5().Digest(data)); string lenstr = data.Length.ToString(); for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++) { HttpURLConnection c = Open("PUT", bucket, key); c.SetRequestProperty("Content-Length", lenstr); c.SetRequestProperty("Content-MD5", md5str); c.SetRequestProperty(X_AMZ_ACL, acl); Authorize(c); c.SetDoOutput(true); c.SetFixedLengthStreamingMode(data.Length); OutputStream os = c.GetOutputStream(); try { os.Write(data); } finally { os.Close(); } switch (HttpSupport.Response(c)) { case HttpURLConnection.HTTP_OK: { return; } case HttpURLConnection.HTTP_INTERNAL_ERROR: { continue; goto default; } default: { throw Error("Writing", key, c); } } } throw MaxAttempts("Writing", key); }
public void Redirect() { string mainStr = "HTTP/" + VersionString() + " " + (int)StatusCode.SEE_OTHER + " " + SonicHTTPStatus.StatusToString(StatusCode.SEE_OTHER) + "\r\n"; mainStr += "Location:" + RedirectLocation + "\r\n\r\n"; byte[] buffer = ToBytes(mainStr); IsRedirectionRequest = true; OutputStream.Write(buffer, 0, buffer.Length); OutputStream.Flush(); OutputStream.Close(); IsRedirectionRequest = false; }
/// <summary> /// Closes the tag manager's streams /// </summary> public void Close() { //if (InCache) return; if (this.InputStream != null) { InputStream.Close(); InputStream = null; } if (this.OutputStream != null) { OutputStream.Close(); OutputStream = null; } }
public static void WriteBytes(OutputStream outputStream, byte[] bytes) { try { outputStream.Write(bytes); outputStream.Close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
public void ShouldCallDelegateAfterBeforeClosed() { bool wasCalled = false; OutputStream outputSaveStream = new OutputStream(delegate { wasCalled = true; }); outputSaveStream.Close(); Assert.IsTrue(wasCalled); }
/// <exception cref="System.IO.IOException"></exception> public static void CopyStream(InputStream @is, OutputStream os) { int n; byte[] buffer = new byte[16384]; while ((n = @is.Read(buffer)) > -1) { os.Write(buffer, 0, n); } os.Close(); @is.Close(); }
/// <summary>Remove xattr</summary> /// <exception cref="System.Exception"/> private void TestRemoveXAttr() { if (!IsLocalFS()) { FileSystem fs = FileSystem.Get(GetProxiedFSConf()); fs.Mkdirs(GetProxiedFSTestDir()); Path path = new Path(GetProxiedFSTestDir(), "foo.txt"); OutputStream os = fs.Create(path); os.Write(1); os.Close(); fs.Close(); string name1 = "user.a1"; byte[] value1 = new byte[] { unchecked ((int)(0x31)), unchecked ((int)(0x32)), unchecked ( (int)(0x33)) }; string name2 = "user.a2"; byte[] value2 = new byte[] { unchecked ((int)(0x41)), unchecked ((int)(0x42)), unchecked ( (int)(0x43)) }; string name3 = "user.a3"; byte[] value3 = null; string name4 = "trusted.a1"; byte[] value4 = new byte[] { unchecked ((int)(0x31)), unchecked ((int)(0x32)), unchecked ( (int)(0x33)) }; string name5 = "a1"; fs = FileSystem.Get(GetProxiedFSConf()); fs.SetXAttr(path, name1, value1); fs.SetXAttr(path, name2, value2); fs.SetXAttr(path, name3, value3); fs.SetXAttr(path, name4, value4); fs.Close(); fs = GetHttpFSFileSystem(); fs.RemoveXAttr(path, name1); fs.RemoveXAttr(path, name3); fs.RemoveXAttr(path, name4); try { fs.RemoveXAttr(path, name5); NUnit.Framework.Assert.Fail("Remove xAttr with incorrect name format should fail." ); } catch (IOException) { } catch (ArgumentException) { } fs = FileSystem.Get(GetProxiedFSConf()); IDictionary <string, byte[]> xAttrs = fs.GetXAttrs(path); fs.Close(); NUnit.Framework.Assert.AreEqual(1, xAttrs.Count); Assert.AssertArrayEquals(value2, xAttrs[name2]); } }
private Stream InternalSendMessage(Message message) { if(!IsAlive) throw new RemotingException("TCP error: Connection closed!"); writer.Write(magic); writer.Write(Version); writer.Write((byte)message.Type); writer.Write(ThisMachineID.ToByteArray()); writer.Write(message.ID.ToByteArray()); foreach(DictionaryEntry entry in message.Headers) { writer.Write((string)entry.Key); writer.Write((string)entry.Value); } writer.Write(""); Stream outStream = new OutputStream(this); if(message.Stream != null) { MemoryStream ms = message.Stream as MemoryStream; if(ms != null) try { outStream.Write(ms.GetBuffer(), 0, (int)ms.Length); } catch(UnauthorizedAccessException) { ms = null; } if(ms == null) { byte[] buffer = new byte[DefaultBufferSize]; while(true) { int read = message.Stream.Read(buffer, 0, buffer.Length); if(read == 0) break; outStream.Write(buffer, 0, read); } } outStream.Close(); return null; } return outStream; }