本文整理汇总了C#中Sharpen.FileInputStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# FileInputStream.Close方法的具体用法?C# FileInputStream.Close怎么用?C# FileInputStream.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sharpen.FileInputStream
的用法示例。
在下文中一共展示了FileInputStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyFile
/// <exception cref="System.IO.IOException"></exception>
public static void CopyFile(FilePath sourceFile, FilePath destFile)
{
if (!destFile.Exists())
{
destFile.CreateNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try
{
source = new FileInputStream(sourceFile).GetChannel();
destination = new FileOutputStream(destFile).GetChannel();
destination.TransferFrom(source, 0, source.Size());
}
finally
{
if (source != null)
{
source.Close();
}
if (destination != null)
{
destination.Close();
}
}
}
示例2: ProcessBytes
public static GifHeaderDirectory ProcessBytes(string file)
{
Com.Drew.Metadata.Metadata metadata = new Com.Drew.Metadata.Metadata();
InputStream stream = new FileInputStream(file);
new GifReader().Extract(new Com.Drew.Lang.StreamReader(stream), metadata);
stream.Close();
GifHeaderDirectory directory = metadata.GetDirectory<GifHeaderDirectory>();
NUnit.Framework.Assert.IsNotNull(directory);
return directory;
}
示例3: ProcessFile
private static Com.Drew.Metadata.Metadata ProcessFile([NotNull] string filePath)
{
FileInputStream inputStream = null;
try
{
inputStream = new FileInputStream(filePath);
return PngMetadataReader.ReadMetadata(inputStream);
}
finally
{
if (inputStream != null)
{
inputStream.Close();
}
}
}
示例4: ReadMetadata
public static Com.Drew.Metadata.Metadata ReadMetadata(FilePath file, Iterable<JpegSegmentMetadataReader> readers)
{
InputStream inputStream = null;
try
{
inputStream = new FileInputStream(file);
return ReadMetadata(inputStream, readers);
}
finally
{
if (inputStream != null)
{
inputStream.Close();
}
}
}
示例5: ProcessFile
/// <exception cref="Com.Drew.Imaging.Png.PngProcessingException"/>
/// <exception cref="System.IO.IOException"/>
public static IList<PngChunk> ProcessFile(string filePath)
{
FileInputStream inputStream = null;
try
{
inputStream = new FileInputStream(filePath);
return Iterables.ToList(new PngChunkReader().Extract(new Com.Drew.Lang.StreamReader(inputStream), null));
}
finally
{
if (inputStream != null)
{
inputStream.Close();
}
}
}
示例6: VisitFile
/// <exception cref="System.IO.IOException"></exception>
public override void VisitFile(FileTreeEntry f)
{
FilePath path = new FilePath(GetCurrentDirectory(), f.GetName());
FileInputStream @in = new FileInputStream(path);
try
{
long sz = @in.GetChannel().Size();
f.SetId(inserter.Insert(Constants.OBJ_BLOB, sz, @in));
inserter.Flush();
}
finally
{
inserter.Release();
@in.Close();
}
}
示例7: ReadSegments
public static JpegSegmentData ReadSegments(FilePath file, Iterable<JpegSegmentType> segmentTypes)
{
FileInputStream stream = null;
try
{
stream = new FileInputStream(file);
return ReadSegments(new Com.Drew.Lang.StreamReader(stream), segmentTypes);
}
finally
{
if (stream != null)
{
stream.Close();
}
}
}
示例8: ReadMetadata
public static Com.Drew.Metadata.Metadata ReadMetadata(FilePath file)
{
FileInputStream stream = null;
try
{
stream = new FileInputStream(file);
return ReadMetadata(stream);
}
finally
{
if (stream != null)
{
stream.Close();
}
}
}
示例9: ProcessBytes
public static PsdHeaderDirectory ProcessBytes([NotNull] string file)
{
Com.Drew.Metadata.Metadata metadata = new Com.Drew.Metadata.Metadata();
InputStream stream = new FileInputStream(new FilePath(file));
try
{
new PsdReader().Extract(new Com.Drew.Lang.StreamReader(stream), metadata);
}
catch (Exception e)
{
stream.Close();
throw;
}
PsdHeaderDirectory directory = metadata.GetFirstDirectoryOfType<PsdHeaderDirectory>();
NUnit.Framework.Assert.IsNotNull(directory);
return directory;
}
示例10: CheckLockedFilesToBeDeleted
public virtual void CheckLockedFilesToBeDeleted()
{
Git git = Git.Wrap(db);
WriteTrashFile("a.txt", "orig");
WriteTrashFile("b.txt", "orig");
git.Add().AddFilepattern("a.txt").AddFilepattern("b.txt").Call();
RevCommit first = git.Commit().SetMessage("added a.txt, b.txt").Call();
// modify and delete files on the master branch
WriteTrashFile("a.txt", "master");
git.Rm().AddFilepattern("b.txt").Call();
RevCommit masterCommit = git.Commit().SetMessage("modified a.txt, deleted b.txt")
.SetAll(true).Call();
// switch back to a side branch
git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
WriteTrashFile("c.txt", "side");
git.Add().AddFilepattern("c.txt").Call();
git.Commit().SetMessage("added c.txt").Call();
// Get a handle to the the file so on windows it can't be deleted.
FileInputStream fis = new FileInputStream(new FilePath(db.WorkTree, "b.txt"));
MergeCommandResult mergeRes = git.Merge().Include(masterCommit).Call();
if (mergeRes.GetMergeStatus().Equals(MergeStatus.FAILED))
{
// probably windows
NUnit.Framework.Assert.AreEqual(1, mergeRes.GetFailingPaths().Count);
NUnit.Framework.Assert.AreEqual(ResolveMerger.MergeFailureReason.COULD_NOT_DELETE
, mergeRes.GetFailingPaths().Get("b.txt"));
}
NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:master]" + "[c.txt, mode:100644, content:side]"
, IndexState(CONTENT));
fis.Close();
}
示例11: CopyCurrentContent
/// <summary>Copy the current file content into the temporary file.</summary>
/// <remarks>
/// Copy the current file content into the temporary file.
/// <p>
/// This method saves the current file content by inserting it into the
/// temporary file, so that the caller can safely append rather than replace
/// the primary file.
/// <p>
/// This method does nothing if the current file does not exist, or exists
/// but is empty.
/// </remarks>
/// <exception cref="System.IO.IOException">
/// the temporary file could not be written, or a read error
/// occurred while reading from the current file. The lock is
/// released before throwing the underlying IO exception to the
/// caller.
/// </exception>
/// <exception cref="Sharpen.RuntimeException">
/// the temporary file could not be written. The lock is released
/// before throwing the underlying exception to the caller.
/// </exception>
public virtual void CopyCurrentContent()
{
RequireLock();
try
{
FileInputStream fis = new FileInputStream(@ref);
try
{
if (fsync)
{
FileChannel @in = fis.GetChannel();
long pos = 0;
long cnt = @in.Size();
while (0 < cnt)
{
long r = os.GetChannel().TransferFrom(@in, pos, cnt);
pos += r;
cnt -= r;
}
}
else
{
byte[] buf = new byte[2048];
int r;
while ((r = fis.Read(buf)) >= 0)
{
os.Write(buf, 0, r);
}
}
}
finally
{
fis.Close();
}
}
catch (FileNotFoundException)
{
}
catch (IOException ioe)
{
// Don't worry about a file that doesn't exist yet, it
// conceptually has no current content to copy.
//
Unlock();
throw;
}
catch (RuntimeException ioe)
{
Unlock();
throw;
}
catch (Error ioe)
{
Unlock();
throw;
}
}
示例12: AssertWorkDir
/// <exception cref="NGit.Errors.CorruptObjectException"></exception>
/// <exception cref="System.IO.IOException"></exception>
public virtual void AssertWorkDir(Dictionary<string, string> i)
{
TreeWalk walk = new TreeWalk(db);
walk.Recursive = true;
walk.AddTree(new FileTreeIterator(db));
string expectedValue;
string path;
int nrFiles = 0;
FileTreeIterator ft;
while (walk.Next())
{
ft = walk.GetTree<FileTreeIterator>(0);
path = ft.EntryPathString;
expectedValue = i.Get(path);
NUnit.Framework.Assert.IsNotNull(expectedValue, "found unexpected file for path "
+ path + " in workdir");
FilePath file = new FilePath(db.WorkTree, path);
NUnit.Framework.Assert.IsTrue(file.Exists());
if (file.IsFile())
{
FileInputStream @is = new FileInputStream(file);
byte[] buffer = new byte[(int)file.Length()];
int offset = 0;
int numRead = 0;
while (offset < buffer.Length && (numRead = @is.Read(buffer, offset, buffer.Length
- offset)) >= 0)
{
offset += numRead;
}
@is.Close();
CollectionAssert.AreEqual (buffer, Sharpen.Runtime.GetBytesForString(i.Get(path)),
"unexpected content for path " + path + " in workDir. ");
nrFiles++;
}
}
NUnit.Framework.Assert.AreEqual(i.Count, nrFiles, "WorkDir has not the right size."
);
}
示例13: WriteTo
/// <exception cref="System.IO.IOException"></exception>
public override void WriteTo(OutputStream @out)
{
if (@out == null)
{
throw new ArgumentException("Output stream may not be null");
}
InputStream @in = new FileInputStream(this.file);
try
{
byte[] tmp = new byte[4096];
int l;
while ((l = @in.Read(tmp)) != -1)
{
@out.Write(tmp, 0, l);
}
@out.Flush();
}
finally
{
@in.Close();
}
}
示例14: OpenObject2
/// <exception cref="System.IO.IOException"></exception>
internal override ObjectLoader OpenObject2(WindowCursor curs, string objectName,
AnyObjectId objectId)
{
try
{
FilePath path = FileFor(objectName);
FileInputStream @in = new FileInputStream(path);
try
{
unpackedObjectCache.Add(objectId);
return UnpackedObject.Open(@in, path, objectId, curs);
}
finally
{
@in.Close();
}
}
catch (FileNotFoundException)
{
unpackedObjectCache.Remove(objectId);
return null;
}
}
示例15: Test2
public virtual void Test2()
{
FilePath packFile = JGitTestUtil.GetTestResourceFile("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack"
);
InputStream @is = new FileInputStream(packFile);
try
{
ObjectDirectoryPackParser p = (ObjectDirectoryPackParser)Index(@is);
p.Parse(NullProgressMonitor.INSTANCE);
PackFile file = p.GetPackFile();
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("02ba32d3649e510002c21651936b7077aa75ffa9"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("0966a434eb1a025db6b71485ab63a3bfbea520b6"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("09efc7e59a839528ac7bda9fa020dc9101278680"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("0a3d7772488b6b106fb62813c4d6d627918d9181"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("1004d0d7ac26fbf63050a234c9b88a46075719d3"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("10da5895682013006950e7da534b705252b03be6"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("1203b03dc816ccbb67773f28b3c19318654b0bc8"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("15fae9e651043de0fd1deef588aa3fbf5a7a41c6"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("16f9ec009e5568c435f473ba3a1df732d49ce8c3"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("1fd7d579fb6ae3fe942dc09c2c783443d04cf21e"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("20a8ade77639491ea0bd667bf95de8abf3a434c8"
)));
NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("2675188fd86978d5bc4d7211698b2118ae3bf658"
)));
}
finally
{
// and lots more...
@is.Close();
}
}