本文整理汇总了C#中Sharpen.FilePath.Length方法的典型用法代码示例。如果您正苦于以下问题:C# FilePath.Length方法的具体用法?C# FilePath.Length怎么用?C# FilePath.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sharpen.FilePath
的用法示例。
在下文中一共展示了FilePath.Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadBytes
public static sbyte[] ReadBytes(FilePath file)
{
int length = (int)file.Length();
// should only be zero if loading from a network or similar
System.Diagnostics.Debug.Assert((length != 0));
sbyte[] bytes = new sbyte[length];
int totalBytesRead = 0;
FileInputStream inputStream = null;
try
{
inputStream = new FileInputStream(file);
while (totalBytesRead != length)
{
int bytesRead = inputStream.Read(bytes, totalBytesRead, length - totalBytesRead);
if (bytesRead == -1)
{
break;
}
totalBytesRead += bytesRead;
}
}
finally
{
if (inputStream != null)
{
inputStream.Close();
}
}
return bytes;
}
示例2: Test001_Initalize
public virtual void Test001_Initalize()
{
FilePath gitdir = new FilePath(trash, Constants.DOT_GIT);
FilePath hooks = new FilePath(gitdir, "hooks");
FilePath objects = new FilePath(gitdir, "objects");
FilePath objects_pack = new FilePath(objects, "pack");
FilePath objects_info = new FilePath(objects, "info");
FilePath refs = new FilePath(gitdir, "refs");
FilePath refs_heads = new FilePath(refs, "heads");
FilePath refs_tags = new FilePath(refs, "tags");
FilePath HEAD = new FilePath(gitdir, "HEAD");
NUnit.Framework.Assert.IsTrue(trash.IsDirectory(), "Exists " + trash);
NUnit.Framework.Assert.IsTrue(hooks.IsDirectory(), "Exists " + hooks);
NUnit.Framework.Assert.IsTrue(objects.IsDirectory(), "Exists " + objects);
NUnit.Framework.Assert.IsTrue(objects_pack.IsDirectory(), "Exists " + objects_pack
);
NUnit.Framework.Assert.IsTrue(objects_info.IsDirectory(), "Exists " + objects_info
);
NUnit.Framework.Assert.AreEqual(2L, objects.ListFiles().Length);
NUnit.Framework.Assert.IsTrue(refs.IsDirectory(), "Exists " + refs);
NUnit.Framework.Assert.IsTrue(refs_heads.IsDirectory(), "Exists " + refs_heads);
NUnit.Framework.Assert.IsTrue(refs_tags.IsDirectory(), "Exists " + refs_tags);
NUnit.Framework.Assert.IsTrue(HEAD.IsFile(), "Exists " + HEAD);
NUnit.Framework.Assert.AreEqual(23, HEAD.Length());
}
示例3: LoadFile
/// <exception cref="System.IO.IOException"></exception>
public static string LoadFile(FilePath f)
{
int length = (int)f.Length();
// don't worry about very long files
char[] buf = new char[length];
new FileReader(f).Read(buf, 0, length);
return new string(buf);
}
示例4: TestWriteThumbnail
public virtual void TestWriteThumbnail()
{
ExifThumbnailDirectory directory = ExifReaderTest.ProcessBytes<ExifThumbnailDirectory>("Tests/Data/manuallyAddedThumbnail.jpg.app1");
Sharpen.Tests.IsTrue(directory.HasThumbnailData());
FilePath thumbnailFile = FilePath.CreateTempFile("thumbnail", ".jpg");
try
{
directory.WriteThumbnail(thumbnailFile.GetAbsolutePath());
FilePath file = new FilePath(thumbnailFile.GetAbsolutePath());
Sharpen.Tests.AreEqual(2970, file.Length());
Sharpen.Tests.IsTrue(file.Exists());
}
finally
{
if (!thumbnailFile.Delete())
{
NUnit.Framework.Assert.Fail("Unable to delete temp thumbnail file.");
}
}
}
示例5: DecodeFromFile
// end finally
// end decodeToFile
/// <summary>
/// Convenience method for reading a base64-encoded
/// file and decoding it.
/// </summary>
/// <remarks>
/// Convenience method for reading a base64-encoded
/// file and decoding it.
/// <p>As of v 2.3, if there is a error,
/// the method will throw an java.io.IOException. <b>This is new to v2.3!</b>
/// In earlier versions, it just returned false, but
/// in retrospect that's a pretty poor way to handle it.</p>
/// </remarks>
/// <param name="filename">Filename for reading encoded data</param>
/// <returns>decoded byte array</returns>
/// <exception cref="System.IO.IOException">if there is an error</exception>
/// <since>2.1</since>
public static byte[] DecodeFromFile(string filename)
{
byte[] decodedData = null;
Base64.InputStream bis = null;
try
{
// Set up some useful variables
FilePath file = new FilePath(filename);
byte[] buffer = null;
int length = 0;
int numBytes = 0;
// Check for size of file
if (file.Length() > int.MaxValue)
{
throw new IOException("File is too big for this convenience method (" + file.Length
() + " bytes).");
}
// end if: file too big for int index
buffer = new byte[(int)file.Length()];
// Open a stream
bis = new Base64.InputStream(new BufferedInputStream(new FileInputStream(file)),
Couchbase.Lite.Support.Base64.Decode);
// Read until done
while ((numBytes = bis.Read(buffer, length, 4096)) >= 0)
{
length += numBytes;
}
// end while
// Save in a variable to return
decodedData = new byte[length];
System.Array.Copy(buffer, 0, decodedData, 0, length);
}
catch (IOException e)
{
// end try
throw;
}
finally
{
// Catch and release to execute finally{}
// end catch: java.io.IOException
try
{
bis.Close();
}
catch (Exception)
{
}
}
// end finally
return decodedData;
}
示例6: TotalDataSize
public long TotalDataSize()
{
FilePath f = new FilePath(path);
long size = f.Length() + attachments.TotalDataSize();
return size;
}
示例7: CheckoutEntry
/// <summary>
/// Updates the file in the working tree with content and mode from an entry
/// in the index.
/// </summary>
/// <remarks>
/// Updates the file in the working tree with content and mode from an entry
/// in the index. The new content is first written to a new temporary file in
/// the same directory as the real file. Then that new file is renamed to the
/// final filename.
/// <p>
/// TODO: this method works directly on File IO, we may need another
/// abstraction (like WorkingTreeIterator). This way we could tell e.g.
/// Eclipse that Files in the workspace got changed
/// </p>
/// </remarks>
/// <param name="repo"></param>
/// <param name="f">
/// the file to be modified. The parent directory for this file
/// has to exist already
/// </param>
/// <param name="entry">the entry containing new mode and content</param>
/// <param name="or">object reader to use for checkout</param>
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
public static void CheckoutEntry(Repository repo, FilePath f, DirCacheEntry entry
, ObjectReader or)
{
ObjectLoader ol = or.Open(entry.GetObjectId());
FilePath parentDir = f.GetParentFile();
FilePath tmpFile = FilePath.CreateTempFile("._" + f.GetName(), null, parentDir);
WorkingTreeOptions opt = repo.GetConfig().Get(WorkingTreeOptions.KEY);
FileOutputStream rawChannel = new FileOutputStream(tmpFile);
OutputStream channel;
if (opt.GetAutoCRLF() == CoreConfig.AutoCRLF.TRUE)
{
channel = new AutoCRLFOutputStream(rawChannel);
}
else
{
channel = rawChannel;
}
try
{
ol.CopyTo(channel);
}
finally
{
channel.Close();
}
FS fs = repo.FileSystem;
if (opt.IsFileMode() && fs.SupportsExecute())
{
if (FileMode.EXECUTABLE_FILE.Equals(entry.RawMode))
{
if (!fs.CanExecute(tmpFile))
{
fs.SetExecute(tmpFile, true);
}
}
else
{
if (fs.CanExecute(tmpFile))
{
fs.SetExecute(tmpFile, false);
}
}
}
if (!tmpFile.RenameTo(f))
{
// tried to rename which failed. Let' delete the target file and try
// again
FileUtils.Delete(f);
if (!tmpFile.RenameTo(f))
{
throw new IOException(MessageFormat.Format(JGitText.Get().couldNotWriteFile, tmpFile
.GetPath(), f.GetPath()));
}
}
entry.LastModified = f.LastModified();
if (opt.GetAutoCRLF() != CoreConfig.AutoCRLF.FALSE)
{
entry.SetLength(f.Length());
}
else
{
// AutoCRLF wants on-disk-size
entry.SetLength((int)ol.GetSize());
}
}
示例8: TestWriteEmptyCommit_RealIndex
public virtual void TestWriteEmptyCommit_RealIndex()
{
FilePath idx = new FilePath(db.Directory, "index");
FilePath lck = new FilePath(db.Directory, "index.lock");
NUnit.Framework.Assert.IsFalse(idx.Exists());
NUnit.Framework.Assert.IsFalse(lck.Exists());
DirCache dc = db.LockDirCache();
NUnit.Framework.Assert.AreEqual(0, lck.Length());
dc.Write();
NUnit.Framework.Assert.AreEqual(12 + 20, lck.Length());
NUnit.Framework.Assert.IsTrue(dc.Commit());
NUnit.Framework.Assert.IsTrue(idx.Exists());
NUnit.Framework.Assert.IsFalse(lck.Exists());
NUnit.Framework.Assert.AreEqual(12 + 20, idx.Length());
}
示例9: AddEntryToBuilder
/// <exception cref="System.IO.IOException"></exception>
private DirCacheEntry AddEntryToBuilder(string path, FilePath file, ObjectInserter
newObjectInserter, DirCacheBuilder builder, int stage)
{
FileInputStream inputStream = new FileInputStream(file);
ObjectId id = newObjectInserter.Insert(Constants.OBJ_BLOB, file.Length(), inputStream
);
inputStream.Close();
DirCacheEntry entry = new DirCacheEntry(path, stage);
entry.SetObjectId(id);
entry.FileMode = FileMode.REGULAR_FILE;
entry.LastModified = file.LastModified();
entry.SetLength((int)file.Length());
builder.Add(entry);
return entry;
}
示例10: GetSizeOfBlob
public long GetSizeOfBlob(BlobKey key)
{
string path = PathForKey(key);
FilePath file = new FilePath(path);
return file.Length();
}
示例11: NewInstance
// DSA
// RSA
// modulus
// public exponent
// private exponent
// private String algname="ssh-dss";
/// <exception cref="NSch.JSchException"></exception>
internal static NSch.IdentityFile NewInstance(string prvfile, string pubfile, JSch
jsch)
{
byte[] prvkey = null;
byte[] pubkey = null;
FilePath file = null;
FileInputStream fis = null;
try
{
file = new FilePath(prvfile);
fis = new FileInputStream(prvfile);
prvkey = new byte[(int)(file.Length())];
int len = 0;
while (true)
{
int i = fis.Read(prvkey, len, prvkey.Length - len);
if (i <= 0)
{
break;
}
len += i;
}
fis.Close();
}
catch (Exception e)
{
try
{
if (fis != null)
{
fis.Close();
}
}
catch (Exception)
{
}
if (e is Exception)
{
throw new JSchException(e.ToString(), (Exception)e);
}
throw new JSchException(e.ToString());
}
string _pubfile = pubfile;
if (pubfile == null)
{
_pubfile = prvfile + ".pub";
}
try
{
file = new FilePath(_pubfile);
fis = new FileInputStream(_pubfile);
pubkey = new byte[(int)(file.Length())];
int len = 0;
while (true)
{
int i = fis.Read(pubkey, len, pubkey.Length - len);
if (i <= 0)
{
break;
}
len += i;
}
fis.Close();
}
catch (Exception e)
{
try
{
if (fis != null)
{
fis.Close();
}
}
catch (Exception)
{
}
if (pubfile != null)
{
// The pubfile is explicitry given, but not accessible.
if (e is Exception)
{
throw new JSchException(e.ToString(), (Exception)e);
}
throw new JSchException(e.ToString());
}
}
return NewInstance(prvfile, prvkey, pubkey, jsch);
}
示例12: ReadFully
// do nothing
/// <summary>Read an entire local file into memory as a byte array.</summary>
/// <remarks>Read an entire local file into memory as a byte array.</remarks>
/// <param name="path">location of the file to read.</param>
/// <param name="max">
/// maximum number of bytes to read, if the file is larger than
/// this limit an IOException is thrown.
/// </param>
/// <returns>complete contents of the requested local file.</returns>
/// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
/// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
/// </exception>
public static byte[] ReadFully(FilePath path, int max)
{
FileInputStream @in = new FileInputStream(path);
try
{
long sz = Math.Max(path.Length(), 1);
if (sz > max)
{
throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path));
}
byte[] buf = new byte[(int)sz];
int valid = 0;
for (; ; )
{
if (buf.Length == valid)
{
if (buf.Length == max)
{
int next = @in.Read();
if (next < 0)
{
break;
}
throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path));
}
byte[] nb = new byte[Math.Min(buf.Length * 2, max)];
System.Array.Copy(buf, 0, nb, 0, valid);
buf = nb;
}
int n = @in.Read(buf, valid, buf.Length - valid);
if (n < 0)
{
break;
}
valid += n;
}
if (valid < buf.Length)
{
byte[] nb = new byte[valid];
System.Array.Copy(buf, 0, nb, 0, valid);
buf = nb;
}
return buf;
}
finally
{
try
{
@in.Close();
}
catch (IOException)
{
}
}
}
示例13: ReadUrl
/// <exception cref="System.IO.IOException"></exception>
private static string ReadUrl(string filePath, string charCoding, bool urlIsFile)
{
int chunkLength;
Stream @is = null;
try
{
if (!urlIsFile)
{
Uri urlObj = new Uri(filePath);
URLConnection uc = urlObj.OpenConnection();
@is = uc.GetInputStream();
chunkLength = uc.GetContentLength();
if (chunkLength <= 0)
{
chunkLength = 1024;
}
if (charCoding == null)
{
string type = uc.GetContentType();
if (type != null)
{
charCoding = GetCharCodingFromType(type);
}
}
}
else
{
FilePath f = new FilePath(filePath);
if (!f.Exists())
{
throw new FileNotFoundException("File not found: " + filePath);
}
else
{
if (!f.CanRead())
{
throw new IOException("Cannot read file: " + filePath);
}
}
long length = f.Length();
chunkLength = (int)length;
if (chunkLength != length)
{
throw new IOException("Too big file size: " + length);
}
if (chunkLength == 0)
{
return string.Empty;
}
@is = new FileInputStream(f);
}
TextReader r;
if (charCoding == null)
{
r = new StreamReader(@is);
}
else
{
r = new StreamReader(@is, charCoding);
}
return ReadReader(r, chunkLength);
}
finally
{
if (@is != null)
{
@is.Close();
}
}
}
示例14: EncodeFromFile
// end decodeFromFile
/// <summary>
/// Convenience method for reading a binary file
/// and base64-encoding it.
/// </summary>
/// <remarks>
/// Convenience method for reading a binary file
/// and base64-encoding it.
/// <p>As of v 2.3, if there is a error,
/// the method will throw an java.io.IOException. <b>This is new to v2.3!</b>
/// In earlier versions, it just returned false, but
/// in retrospect that's a pretty poor way to handle it.</p>
/// </remarks>
/// <param name="filename">Filename for reading binary data</param>
/// <returns>base64-encoded string</returns>
/// <exception cref="System.IO.IOException">if there is an error</exception>
/// <since>2.1</since>
public static string EncodeFromFile(string filename)
{
string encodedData = null;
Base64.InputStream bis = null;
try
{
// Set up some useful variables
FilePath file = new FilePath(filename);
byte[] buffer = new byte[Math.Max((int)(file.Length() * 1.4 + 1), 40)];
// Need max() for math on small files (v2.2.1); Need +1 for a few corner cases (v2.3.5)
int length = 0;
int numBytes = 0;
// Open a stream
bis = new Base64.InputStream(new BufferedInputStream(new FileInputStream(file)),
Couchbase.Lite.Support.Base64.Encode);
// Read until done
while ((numBytes = bis.Read(buffer, length, 4096)) >= 0)
{
length += numBytes;
}
// end while
// Save in a variable to return
encodedData = Sharpen.Runtime.GetStringForBytes(buffer, 0, length, Couchbase.Lite.Support.Base64
.PreferredEncoding);
}
catch (IOException e)
{
// end try
throw;
}
finally
{
// Catch and release to execute finally{}
// end catch: java.io.IOException
try
{
bis.Close();
}
catch (Exception)
{
}
}
// end finally
return encodedData;
}
示例15: Main
/// <summary>An application entry point.</summary>
/// <remarks>
/// An application entry point. Takes the name of one or more files as arguments and prints the contents of all
/// metadata directories to <code>System.out</code>.
/// <p/>
/// If <code>-thumb</code> is passed, then any thumbnail data will be written to a file with name of the
/// input file having <code>.thumb.jpg</code> appended.
/// <p/>
/// If <code>-wiki</code> is passed, then output will be in a format suitable for Google Code's wiki.
/// <p/>
/// If <code>-hex</code> is passed, then the ID of each tag will be displayed in hexadecimal.
/// </remarks>
/// <param name="args">the command line arguments</param>
/// <exception cref="Com.Drew.Metadata.MetadataException"/>
/// <exception cref="System.IO.IOException"/>
public static void Main(string[] args)
{
ICollection<string> argList = new AList<string>(Arrays.AsList(args));
bool thumbRequested = argList.Remove("-thumb");
bool wikiFormat = argList.Remove("-wiki");
bool showHex = argList.Remove("-hex");
if (argList.Count < 1)
{
string version = typeof(Com.Drew.Imaging.ImageMetadataReader).Assembly.GetImplementationVersion();
System.Console.Out.Println("metadata-extractor version " + version);
System.Console.Out.Println();
System.Console.Out.Println(Sharpen.Extensions.StringFormat("Usage: java -jar metadata-extractor-%s.jar <filename> [<filename>] [-thumb] [-wiki] [-hex]", version == null ? "a.b.c" : version));
System.Environment.Exit(1);
}
foreach (string filePath in argList)
{
long startTime = Runtime.NanoTime();
FilePath file = new FilePath(filePath);
if (!wikiFormat && argList.Count > 1)
{
System.Console.Out.Printf("\n***** PROCESSING: %s\n%n", filePath);
}
Com.Drew.Metadata.Metadata metadata = null;
try
{
metadata = Com.Drew.Imaging.ImageMetadataReader.ReadMetadata(file);
}
catch (Exception e)
{
Sharpen.Runtime.PrintStackTrace(e, System.Console.Error);
System.Environment.Exit(1);
}
long took = Runtime.NanoTime() - startTime;
if (!wikiFormat)
{
System.Console.Out.Printf("Processed %.3f MB file in %.2f ms%n%n", file.Length() / (1024d * 1024), took / 1000000d);
}
if (wikiFormat)
{
string fileName = file.GetName();
string urlName = StringUtil.UrlEncode(fileName);
ExifIFD0Directory exifIFD0Directory = metadata.GetDirectory<ExifIFD0Directory>();
string make = exifIFD0Directory == null ? string.Empty : StringUtil.EscapeForWiki(exifIFD0Directory.GetString(ExifIFD0Directory.TagMake));
string model = exifIFD0Directory == null ? string.Empty : StringUtil.EscapeForWiki(exifIFD0Directory.GetString(ExifIFD0Directory.TagModel));
System.Console.Out.Println();
System.Console.Out.Println("-----");
System.Console.Out.Println();
System.Console.Out.Printf("= %s - %s =%n", make, model);
System.Console.Out.Println();
System.Console.Out.Printf("<a href=\"http://sample-images.metadata-extractor.googlecode.com/git/%s\">%n", urlName);
System.Console.Out.Printf("<img src=\"http://sample-images.metadata-extractor.googlecode.com/git/%s\" width=\"300\"/><br/>%n", urlName);
System.Console.Out.Println(StringUtil.EscapeForWiki(fileName));
System.Console.Out.Println("</a>");
System.Console.Out.Println();
System.Console.Out.Println("|| *Directory* || *Tag Id* || *Tag Name* || *Extracted Value* ||");
}
// iterate over the metadata and print to System.out
foreach (Com.Drew.Metadata.Directory directory in metadata.GetDirectories())
{
string directoryName = directory.GetName();
foreach (Tag tag in directory.GetTags())
{
string tagName = tag.GetTagName();
string description = tag.GetDescription();
// truncate the description if it's too long
if (description != null && description.Length > 1024)
{
description = Sharpen.Runtime.Substring(description, 0, 1024) + "...";
}
if (wikiFormat)
{
System.Console.Out.Printf("||%s||0x%s||%s||%s||%n", StringUtil.EscapeForWiki(directoryName), Sharpen.Extensions.ToHexString(tag.GetTagType()), StringUtil.EscapeForWiki(tagName), StringUtil.EscapeForWiki(description));
}
else
{
if (showHex)
{
System.Console.Out.Printf("[%s - %s] %s = %s%n", directoryName, tag.GetTagTypeHex(), tagName, description);
}
else
{
System.Console.Out.Printf("[%s] %s = %s%n", directoryName, tagName, description);
}
}
}
//.........这里部分代码省略.........