public static Stream toBuffered(Stream output, Long bufSize) { if (bufSize == null || bufSize.longValue() == 0) return output; else return new BufferedStream(output, bufSize.intValue()); }
////////////////////////////////////////////////////////////////////////// // Constructor ////////////////////////////////////////////////////////////////////////// public static SysInStream make(Stream input, Long bufSize) { if (bufSize == null || bufSize.longValue() == 0) return new SysInStream(input); else return new SysInStream(new BufferedStream(input, bufSize.intValue())); }
public override InStream @in(Long bufSize) { try { System.IO.Stream ins; if (m_parent is Zip) { // never buffer if using ZipInputStream ins = new ZipEntryInputStream((m_parent as Zip).m_zipIn); } else { ins = (m_parent as ZipFile).GetInputStream(m_entry); // buffer if specified if (bufSize != null && bufSize.longValue() != 0) ins = new System.IO.BufferedStream(ins, bufSize.intValue()); } // return as fan stream return new SysInStream(ins); } catch (System.IO.IOException e) { throw IOErr.make(e).val; } }
////////////////////////////////////////////////////////////////////////// // Constructor ////////////////////////////////////////////////////////////////////////// internal MmapBuf(File file, string mode, long pos, Long size) { this.m_file = file; // if size is null, use file size //if (size == null) size = size(); //this.m_mmap = mmap; //this.m_out = new MmapBufOutStream(); //this.m_in = new MmapBufInStream(); }
////////////////////////////////////////////////////////////////////////// // Methods ////////////////////////////////////////////////////////////////////////// public TcpListener bind(TcpListener fan, IpAddr addr, Long port, long backlog) { IPAddress dotnetAddr = (addr == null) ? IPAddress.Any : addr.m_peer.m_dotnet; int dotnetPort = (port == null) ? 0 : port.intValue(); m_dotnet = new System.Net.Sockets.TcpListener(dotnetAddr, dotnetPort); m_dotnet.Server.ReceiveBufferSize = (int)m_receiveBufferSize; m_dotnet.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, m_reuseAddr); m_dotnet.Start((int)backlog); m_bound = true; return fan; }
////////////////////////////////////////////////////////////////////////// // Communication ////////////////////////////////////////////////////////////////////////// public TcpSocket bind(TcpSocket fan, IpAddr addr, Long port) { try { IPAddress dotnetAddr = (addr == null) ? IPAddress.Any : addr.m_peer.m_dotnet; int dotnetPort = (port == null) ? 0 : port.intValue(); m_dotnet.Bind(new IPEndPoint(dotnetAddr, dotnetPort)); return fan; } catch (SocketException e) { throw IOErr.make(e).val; } }
public static Long toDigit(long self, long radix) { int val = (int)self; int r = (int)radix; if (val < 0 || val >= r) { return(null); } if (val < 10) { return(Long.valueOf(val + '0')); } return(Long.valueOf(val - 10 + 'a')); }
public override Long readBuf(Buf buf, long n) { try { long read = buf.pipeFrom(inStream, n); if (read <= 0) { return(null); } return(Long.valueOf(read)); } catch (IOException e) { throw IOErr.make(e).val; } }
public Long last() { if (isEmpty()) { return(null); } if (!m_exclusive) { return(Long.valueOf(m_end)); } if (m_start < m_end) { return(Long.valueOf(m_end - 1)); } return(Long.valueOf(m_end + 1)); }
public override Long readBuf(Buf other, long n) { try { long read = other.pipeFrom(p.m_stream, n); if (read < 0) { return(null); } return(Long.valueOf(read)); } catch (IOException e) { throw IOErr.make(e).val; } }
public Long indexr(object val, long off) { if (m_size == 0) { return(null); } int start = (int)off; if (start < 0) { start = m_size + start; } if (start >= m_size) { throw IndexErr.make(off).val; } try { if (val == null) { for (int i = start; i >= 0; --i) { if (m_values[i] == null) { return(Long.valueOf(i)); } } } else { for (int i = start; i >= 0; --i) { object obj = m_values[i]; if (obj != null && obj.Equals(val)) { return(Long.valueOf(i)); } } } return(null); } catch (IndexOutOfRangeException) { throw IndexErr.make(off).val; } }
public static Long indexrIgnoreCase(string self, string s, long off) { int vlen = self.Length, slen = s.Length; int r = -1; int i = (int)off; if (i < 0) { i = vlen + i; } if (i + slen >= vlen) { i = vlen - slen; } int first = s[0]; for (; i >= 0; --i) { // test first char if (neic(first, self[i])) { continue; } // test remainder of chars r = i; for (int si = 1, vi = i + 1; si < slen; ++si, ++vi) { if (neic(s[si], self[vi])) { r = -1; break; } } if (r >= 0) { break; } } if (r < 0) { return(null); } return(Long.valueOf(r)); }
public static string toRadix(long self, long radix, Long width) { string s = Convert.ToString(self, (int)radix); if (width != null && s.Length < width.intValue()) { StringBuilder sb = new StringBuilder(width.intValue()); int zeros = width.intValue() - s.Length; for (int i = 0; i < zeros; ++i) { sb.Append('0'); } sb.Append(s); s = sb.ToString(); } return(s); }
public static Long indexr(string self, string s, long off) { int i = (int)off; if (i < 0) { i = self.Length + i; } int r; if (s.Length == 1) { r = self.LastIndexOf(s[0], i); } else { // this doesn't match Java impl - so we have to roll // our own - prob alot of room for improvement... //r = val.LastIndexOf(sval, i, StringComparison.InvariantCulture); int len = self.Length; int slen = s.Length; if (len < slen) { return(null); } r = -1; for (; i >= 0; i--) { if (nStartsWith(self, s, i)) { r = i; break; } } } if (r < 0) { return(null); } return(Long.valueOf(r)); }
public override OutStream @out(bool append, Long bufSize) { try { FileInfo f = (FileInfo)m_file; System.IO.Directory.CreateDirectory(f.DirectoryName); System.IO.Stream fout = f.Open( append ? System.IO.FileMode.Append : System.IO.FileMode.Create, System.IO.FileAccess.Write); System.IO.Stream bout = SysOutStream.toBuffered(fout, bufSize); m_file.Refresh(); return(new LocalFileOutStream(bout /*, fout.getFD()*/)); } catch (System.IO.IOException e) { throw IOErr.make(e).val; } }
////////////////////////////////////////////////////////////////////////// // Documentation ////////////////////////////////////////////////////////////////////////// public string doc() { if (!m_docLoaded) { try { Stream input = fpod.m_store.read("doc/pod.fandoc"); if (input != null) { m_doc = SysInStream.make(input, Long.valueOf(1024L)).readAllStr(); } } catch (Exception e) { Err.dumpStack(e); } m_docLoaded = true; } return(m_doc); }
/** * Parse an un-interned unit: * unit := <name> [";" <symbol> [";" <dim> [";" <scale> [";" <offset>]]]] */ private static Unit parseUnit(string s) { string idStrs = s; int c = s.IndexOf(';'); if (c > 0) { idStrs = s.Substring(0, c); } List ids = FanStr.split(idStrs, Long.valueOf(',')); if (c < 0) { return(new Unit(ids, m_dimensionless, 1, 0)); } string dim = s = s.Substring(c + 1).Trim(); c = s.IndexOf(';'); if (c < 0) { return(new Unit(ids, parseDim(dim), 1, 0)); } dim = s.Substring(0, c).Trim(); string scale = s = s.Substring(c + 1).Trim(); c = s.IndexOf(';'); if (c < 0) { return(new Unit(ids, parseDim(dim), Double.parseDouble(scale), 0)); } scale = s.Substring(0, c).Trim(); string offset = s.Substring(c + 1).Trim(); return(new Unit(ids, parseDim(dim), Double.parseDouble(scale), Double.parseDouble(offset))); }
public virtual Buf readBufFully(Buf buf, long n) { if (buf == null) { buf = Buf.make(n); } long total = n; long got = 0; while (got < total) { Long r = readBuf(buf, total - got); if (r == null || r.longValue() == 0) { throw IOErr.make("Unexpected end of stream").val; } got += r.longValue(); } buf.flip(); return(buf); }
public List moveTo(object item, long toIndex) { modify(); Long curIndex = index(item); if (curIndex == null) { return(this); } if (curIndex.longValue() == toIndex) { return(this); } removeAt(curIndex.longValue()); if (toIndex == -1) { return(add(item)); } if (toIndex < 0) { ++toIndex; } return(insert(toIndex, item)); }
public virtual string readLine(Long max) { // max limit int maxChars = System.Int32.MaxValue; if (max != null) { long maxLong = max.longValue(); if (maxLong == 0L) { return(""); } if (maxLong < 0) { throw ArgErr.make("Invalid max: " + max).val; } if (maxLong < System.Int32.MaxValue) { maxChars = (int)maxLong; } } // read first char, if at end of file bail int c = rChar(); if (c < 0) { return(null); } // loop reading chars until we hit newline // combo or end of stream StringBuilder buf = new StringBuilder(256); while (true) { // check for \n, \r\n, or \r if (c == '\n') { break; } if (c == '\r') { c = rChar(); if (c >= 0 && c != '\n') { unreadChar(c); } break; } // Append to working buffer buf.Append((char)c); if (buf.Length >= maxChars) { break; } // read next char c = rChar(); if (c < 0) { break; } } return(buf.ToString()); }
public string readStrToken(Long max, Func f) { return m_in.readStrToken(FanInt.Chunk, f); }
public void fA(Native t, Long x) { m_fA = x; }
public override OutStream @out(bool append, Long bufSize) { try { FileInfo f = (FileInfo)m_file; System.IO.Directory.CreateDirectory(f.DirectoryName); System.IO.Stream fout = f.Open( append ? System.IO.FileMode.Append : System.IO.FileMode.Create, System.IO.FileAccess.Write); System.IO.Stream bout = SysOutStream.toBuffered(fout, bufSize); m_file.Refresh(); return new LocalFileOutStream(bout/*, fout.getFD()*/); } catch (System.IO.IOException e) { throw IOErr.make(e).val; } }
public string readLine(Long max) { return m_in.readLine(max); }
public static List split(string self, Long separator, bool trim) { if (separator == null) return splitws(self); int sep = separator.intValue(); List toks = new List(Sys.StrType, 16); int len = self.Length; int x = 0; for (int i=0; i<len; ++i) { if (self[i] != sep) continue; if (x <= i) toks.add(splitStr(self, x, i, trim)); x = i+1; } if (x <= len) toks.add(splitStr(self, x, len, trim)); return toks; }
public static string toCode(string self, Long quote, bool escapeUnicode) { StringBuilder s = new StringBuilder(self.Length+10); // opening quote bool escu = escapeUnicode; int q = 0; if (quote != null) { q = quote.intValue(); s.Append((char)q); } // NOTE: these escape sequences are duplicated in ObjEncoder int len = self.Length; for (int i=0; i<len; ++i) { int c = self[i]; switch (c) { case '\n': s.Append('\\').Append('n'); break; case '\r': s.Append('\\').Append('r'); break; case '\f': s.Append('\\').Append('f'); break; case '\t': s.Append('\\').Append('t'); break; case '\\': s.Append('\\').Append('\\'); break; case '"': if (q == '"') s.Append('\\').Append('"'); else s.Append((char)c); break; case '`': if (q == '`') s.Append('\\').Append('`'); else s.Append((char)c); break; case '\'': if (q == '\'') s.Append('\\').Append('\''); else s.Append((char)c); break; case '$': s.Append('\\').Append('$'); break; default: if (c < ' ' || (escu && c > 127)) { s.Append('\\').Append('u') .Append((char)hex((c>>12)&0xf)) .Append((char)hex((c>>8)&0xf)) .Append((char)hex((c>>4)&0xf)) .Append((char)hex(c&0xf)); } else { s.Append((char)c); } break; } } // closing quote if (q != 0) s.Append((char)q); return s.ToString(); }
public override Buf mmap(string mode, long pos, Long size) { throw UnsupportedErr.make("ZipEntryFile.mmap").val; }
public override OutStream @out(bool append, Long bufSize) { throw IOErr.make("ZipEntryFile is readonly").val; }
public virtual string readLine(Long max) { // max limit int maxChars = System.Int32.MaxValue; if (max != null) { long maxLong = max.longValue(); if (maxLong == 0L) return ""; if (maxLong < 0) throw ArgErr.make("Invalid max: " + max).val; if (maxLong < System.Int32.MaxValue) maxChars = (int)maxLong; } // read first char, if at end of file bail int c = rChar(); if (c < 0) return null; // loop reading chars until we hit newline // combo or end of stream StringBuilder buf = new StringBuilder(256); while (true) { // check for \n, \r\n, or \r if (c == '\n') break; if (c == '\r') { c = rChar(); if (c >= 0 && c != '\n') unreadChar(c); break; } // Append to working buffer buf.Append((char)c); if (buf.Length >= maxChars) break; // read next char c = rChar(); if (c < 0) break; } return buf.ToString(); }
private void normalizeHttp() { if (scheme == null || scheme != "http") return; // port 80 -> null if (port != null && port.longValue() == 80) port = null; // if path is "" -> "/" if (pathStr == null || pathStr.Length == 0) { pathStr = FanStr.m_ascii['/']; if (path == null) path = emptyPath(); } }
public string readStrToken(Long max, Func f) { return(m_in.readStrToken(FanInt.Chunk, f)); }
public string readStrToken(Long max) { return(m_in.readStrToken(max)); }
public string readLine(Long max) { return(m_in.readLine(max)); }
public static string toHex(long self, Long width) { long val = self; string s = val.ToString("X").ToLower(); if (width != null && s.Length < width.intValue()) { StringBuilder sb = new StringBuilder(width.intValue()); int zeros = width.intValue() - s.Length; for (int i=0; i<zeros; ++i) sb.Append('0'); sb.Append(s); s = sb.ToString(); } return s; }
////////////////////////////////////////////////////////////////////////// // InStream ////////////////////////////////////////////////////////////////////////// public override Long read() { int n = r(); return(n < 0 ? null : Long.valueOf(n)); }
public static List split(string self, Long separator) { return(split(self, separator, true)); }
public static string toCode(string self, Long quote) { return(toCode(self, quote, false)); }
public static string toCode(string self, Long quote) { return toCode(self, quote, false); }
public void setOutBufferSize(TcpSocket fan, Long v) { if (m_in != null) throw Err.make("Must set outBufSize before connection").val; m_outBufSize = (v == null) ? 0 : v.intValue(); }
public override InStream @in(Long bufSize) { try { System.IO.Stream stream = (m_file as FileInfo).OpenRead(); return SysInStream.make(stream, bufSize); } catch (System.IO.IOException e) { throw IOErr.make(e).val; } }
public static string toCode(string self, Long quote, bool escapeUnicode) { StringBuilder s = new StringBuilder(self.Length + 10); // opening quote bool escu = escapeUnicode; int q = 0; if (quote != null) { q = quote.intValue(); s.Append((char)q); } // NOTE: these escape sequences are duplicated in ObjEncoder int len = self.Length; for (int i = 0; i < len; ++i) { int c = self[i]; switch (c) { case '\n': s.Append('\\').Append('n'); break; case '\r': s.Append('\\').Append('r'); break; case '\f': s.Append('\\').Append('f'); break; case '\t': s.Append('\\').Append('t'); break; case '\\': s.Append('\\').Append('\\'); break; case '"': if (q == '"') { s.Append('\\').Append('"'); } else { s.Append((char)c); } break; case '`': if (q == '`') { s.Append('\\').Append('`'); } else { s.Append((char)c); } break; case '\'': if (q == '\'') { s.Append('\\').Append('\''); } else { s.Append((char)c); } break; case '$': s.Append('\\').Append('$'); break; default: if (c < ' ' || (escu && c > 127)) { s.Append('\\').Append('u') .Append((char)hex((c >> 12) & 0xf)) .Append((char)hex((c >> 8) & 0xf)) .Append((char)hex((c >> 4) & 0xf)) .Append((char)hex(c & 0xf)); } else { s.Append((char)c); } break; } } // closing quote if (q != 0) { s.Append((char)q); } return(s.ToString()); }
public override Buf mmap(string mode, long pos, Long size) { try { // map mode /* MmapBuf.FileRights mode; if (mode.val.equals("r")) { mode = MmapBuff.FileRights.Read; } else if (mode.val.equals("rw")) { mode = MmapBuff.FileRights.ReadWrite; } else if (mode.val.equals("p")) throw ArgErr.make("Private mode not supported.").val; else throw ArgErr.make("Invalid mode: " + mode).val; // verify mode is 'r' or 'rw' if (mode.val.equals("p")) throw ArgErr.make("Private mode not supported.").val; if (!mode.val.equals("r") || !mode.val.equals("rw")) throw ArgErr.make("Invalid mode: " + mode).val; // if size is null, use file size if (size == null) size = size(); // traverse the various Java APIs //RandomAccessFile fp = new RandomAccessFile(file, rw); //FileChannel chan = fp.getChannel(); //MappedByteBuffer mmap = chan.map(mm, pos.val, size.val); */ return new MmapBuf(this, mode, pos, size); } catch (System.IO.IOException e) { throw IOErr.make(e).val; } }
public virtual string readStrToken(Long max) { return readStrToken(max, null); }
public string readStrToken(Long max) { return m_in.readStrToken(max); }
internal void setAuth(Uri x) { userInfo = x.m_userInfo; host = x.m_host; port = x.m_port; }
public virtual long pipe(OutStream output, Long n) { return(pipe(output, n, true)); }
private void normalizeScheme(int p) { // port 80 -> null if (port != null && port.longValue() == p) port = null; // if path is "" -> "/" if (pathStr == null || pathStr.Length == 0) { pathStr = FanStr.m_ascii['/']; if (path == null) path = emptyPath(); } }
public virtual Long readChar() { int ch = m_charsetDecoder.decode(this); return(ch < 0 ? null : Long.valueOf(ch)); }
////////////////////////////////////////////////////////////////////////// // Iterators ////////////////////////////////////////////////////////////////////////// public static List chars(string self) { int len = self.Length; if (len == 0) return Sys.IntType.emptyList(); Long[] chars = new Long[len]; for (int i=0; i<len; ++i) chars[i] = Long.valueOf(self[i]); return new List(Sys.IntType, chars); }
public virtual string readStrToken(Long max) { return(readStrToken(max, null)); }
public static List split(string self, Long separator) { return split(self, separator, true); }
////////////////////////////////////////////////////////////////////////// // Constructor ////////////////////////////////////////////////////////////////////////// public static SysOutStream make(Stream output, Long bufSize) { return(new SysOutStream(toBuffered(output, bufSize))); }
////////////////////////////////////////////////////////////////////////// // Constructor ////////////////////////////////////////////////////////////////////////// public static SysOutStream make(Stream output, Long bufSize) { return new SysOutStream(toBuffered(output, bufSize)); }
////////////////////////////////////////////////////////////////////////// // Java Constructors ////////////////////////////////////////////////////////////////////////// private Uri(Sections x) { m_scheme = x.scheme; m_userInfo = x.userInfo; m_host = x.host; m_port = x.port; m_pathStr = x.pathStr; m_path = x.path.ro(); m_queryStr = x.queryStr; m_query = x.query.ro(); m_frag = x.frag; m_str = x.str != null ? x.str : new Encoder(this, false).encode(); }
public virtual string readStrToken(Long max, Func f) { // max limit int maxChars = (max != null) ? max.intValue() : System.Int32.MaxValue; if (maxChars <= 0) return string.Empty; // read first char, if at end of file bail int c = rChar(); if (c < 0) return null; // loop reading chars until our closure returns false StringBuilder buf = new StringBuilder(); while (true) { // check for \n, \r\n, or \r bool terminate; if (f == null) terminate = FanInt.isSpace(c); else terminate = ((Boolean)f.call(c)).booleanValue(); if (terminate) { unreadChar(c); break; } // Append to working buffer buf.Append((char)c); if (buf.Length >= maxChars) break; // read next char c = rChar(); if (c < 0) break; } return buf.ToString(); }
public static string toHex(long self, Long width) { return(toRadix(self, 16, width)); }
public static string toCode(string self) { return(toCode(self, Long.valueOf('"'), false)); }