public static Stream toBuffered(Stream output, Long bufSize) { if (bufSize == null || bufSize.longValue() == 0) return output; else return new BufferedStream(output, bufSize.intValue()); }
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); }
////////////////////////////////////////////////////////////////////////// // 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; } }
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; } }
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); }
////////////////////////////////////////////////////////////////////////// // C# Stream ////////////////////////////////////////////////////////////////////////// /// <summary> /// Read a byte using a Java primitive int. Most /// reads route to this method for efficient mapping to /// a java.io.InputStream. If we aren't overriding this /// method, then route back to read() for the subclass /// to handle. /// </summary> public virtual int r() { Long n = read(); if (n == null) { return(-1); } return(n.intValue()); }
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()); }
////////////////////////////////////////////////////////////////////////// // 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; }
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()))); } }
// Methods public override int Read(byte[] b, int off, int len) { buf.m_buf = b; buf.m_pos = off; buf.m_size = b.Length; Long n = ins.readBuf(buf, len); buf.m_buf = null; if (n == null) { return(-1); } return(n.intValue()); }
////////////////////////////////////////////////////////////////////////// // Communication ////////////////////////////////////////////////////////////////////////// public UdpSocket bind(UdpSocket fan, IpAddr addr, Long port) { try { if (m_dotnet == null) m_dotnet = createSocket(); 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 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 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 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) { 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; }
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 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 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; }