iTextSharp.text.io.StreamUtil.GetResourceStream C# (CSharp) Метод

GetResourceStream() публичный статический Метод

public static GetResourceStream ( string key ) : Stream
key string
Результат Stream
        public static Stream GetResourceStream(string key)
        {
            Stream istr = null;
            // Try to use resource loader to load the properties file.
            try
            {
                Assembly assm = Assembly.GetExecutingAssembly();
                istr = assm.GetManifestResourceStream(key);
            }
            catch
            {
            }
            if(istr != null)
                return istr;
            int count;
            lock(resourceSearch) {
                count = resourceSearch.Count;
            }
            for(int k = 0; k < count; ++k) {
                object obj;
                lock(resourceSearch) {
                    obj = resourceSearch[k];
                }
                try {
                    if(obj is Assembly) {
                        istr = ((Assembly)obj).GetManifestResourceStream(key);
                        if(istr != null)
                            return istr;
                    } else if(obj is string) {
                        string dir = (string)obj;
                        try {
                            istr = Assembly.LoadFrom(dir).GetManifestResourceStream(key);
                        }
                        catch { }
                        if(istr != null)
                            return istr;
                        string modkey = key.Replace('.', '/');
                        string fullPath = Path.Combine(dir, modkey);
                        if(File.Exists(fullPath)) {
                            return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                        }
                        int idx = modkey.LastIndexOf('/');
                        if(idx >= 0) {
                            modkey = modkey.Substring(0, idx) + "." + modkey.Substring(idx + 1);
                            fullPath = Path.Combine(dir, modkey);
                            if(File.Exists(fullPath))
                                return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                        }
                    }
                } catch { }
            }

            return istr;
        }
    }

Usage Example

Пример #1
0
 /**
  * Creates a new {@link RandomAccessSource} by reading the specified file/resource into memory
  * @param filename the name of the resource to read
  * @return the newly created {@link RandomAccessSource}
  * @throws IOException if reading the underling file or stream fails
  */
 private IRandomAccessSource CreateByReadingToMemory(String filename) {
     //TODO: seems odd that we are using BaseFont here...
     Stream inp = StreamUtil.GetResourceStream(filename);
     if (inp == null)
         throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filename));
     return CreateByReadingToMemory(inp);
 }