public void DumpFields(System.IO.BufferedStream stream) { StringBuilder fieldBuilder = new StringBuilder(); this.BuildFields(ref fieldBuilder); byte[] fieldBytes = Encoding.UTF8.GetBytes(fieldBuilder.ToString()); stream.Write(fieldBytes, 0, fieldBytes.Length); }
// Uncomment these cases & run them on an older Lucene // version, to generate an index to test backwards // compatibility. Then, cd to build/test/index.cfs and // run "zip index.<VERSION>.cfs.zip *"; cd to // build/test/index.nocfs and run "zip // index.<VERSION>.nocfs.zip *". Then move those 2 zip // files to your trunk checkout and add them to the // oldNames array. /* * public void testCreatePreLocklessCFS() throws IOException { * createIndex("index.cfs", true); * } * * public void testCreatePreLocklessNoCFS() throws IOException { * createIndex("index.nocfs", false); * } */ /* Unzips dirName + ".zip" --> dirName, removing dirName * first */ public virtual void Unzip(System.String zipName, System.String destDirName) { #if SHARP_ZIP_LIB // get zip input stream ICSharpCode.SharpZipLib.Zip.ZipInputStream zipFile; zipFile = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipName + ".zip")); // get dest directory name System.String dirName = FullDir(destDirName); System.IO.FileInfo fileDir = new System.IO.FileInfo(dirName); // clean up old directory (if there) and create new directory RmDir(fileDir.FullName); System.IO.Directory.CreateDirectory(fileDir.FullName); // copy file entries from zip stream to directory ICSharpCode.SharpZipLib.Zip.ZipEntry entry; while ((entry = zipFile.GetNextEntry()) != null) { System.IO.Stream streamout = new System.IO.BufferedStream(new System.IO.FileStream(new System.IO.FileInfo(System.IO.Path.Combine(fileDir.FullName, entry.Name)).FullName, System.IO.FileMode.Create)); byte[] buffer = new byte[8192]; int len; while ((len = zipFile.Read(buffer, 0, buffer.Length)) > 0) { streamout.Write(buffer, 0, len); } streamout.Close(); } zipFile.Close(); #else Assert.Fail("Needs integration with SharpZipLib"); #endif }
// Uncomment these cases & run in a pre-lockless checkout // to create indices: /* public void testCreatePreLocklessCFS() throws IOException { CreateIndex("src/test/org/apache/lucene/index/index.prelockless.cfs", true); } public void testCreatePreLocklessNoCFS() throws IOException { CreateIndex("src/test/org/apache/lucene/index/index.prelockless.nocfs", false); } */ /* Unzips dirName + ".zip" --> dirName, removing dirName first */ public virtual void Unzip(System.String zipName, System.String destDirName) { #if SHARP_ZIP_LIB // get zip input stream ICSharpCode.SharpZipLib.Zip.ZipInputStream zipFile; zipFile = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipName + ".zip")); // get dest directory name System.String dirName = FullDir(destDirName); System.IO.FileInfo fileDir = new System.IO.FileInfo(dirName); // clean up old directory (if there) and create new directory RmDir(fileDir.FullName); System.IO.Directory.CreateDirectory(fileDir.FullName); // copy file entries from zip stream to directory ICSharpCode.SharpZipLib.Zip.ZipEntry entry; while ((entry = zipFile.GetNextEntry()) != null) { System.IO.Stream streamout = new System.IO.BufferedStream(new System.IO.FileStream(new System.IO.FileInfo(System.IO.Path.Combine(fileDir.FullName, entry.Name)).FullName, System.IO.FileMode.Create)); byte[] buffer = new byte[8192]; int len; while ((len = zipFile.Read(buffer, 0, buffer.Length)) > 0) { streamout.Write(buffer, 0, len); } streamout.Close(); } zipFile.Close(); #else Assert.Fail("Needs integration with SharpZipLib"); #endif }
/// <summary> /// 进入消息等待 /// </summary> public void Process() { //用户发送队列 m_userQueue = new RingQueue <byte>(1024); //vt220待解析数据 m_telnetDataQueue = new RingQueue <byte>(8192); //消息处理 new System.Threading.Thread(new System.Threading.ThreadStart(delegate() { //接收缓存队列 var recvQueue = new RingQueue <byte>(8192); //发送缓存队列 var sendQueue = new RingQueue <byte>(1024); var io = m_conn.GetStream(); var sendStream = new System.IO.BufferedStream(io); var recvStream = new System.IO.BufferedStream(io); while (m_conn != null && m_conn.Connected) { //接收服务端数据 while (io.DataAvailable && recvQueue.Available > 0) { var b = io.ReadByte(); if (b == -1) { break; } recvQueue.Push((byte)b); } //解析Telnet协议 并 响应服务器 ParseTelnetCommand(recvQueue, sendQueue, m_telnetDataQueue); //解析VT220协议 ParseVT220Command(m_telnetDataQueue); //客户端发送数据 while (sendQueue.Count > 0 && m_conn.Connected) { var data = sendQueue.ToArray(); sendStream.Write(data, 0, data.Length); sendStream.Flush(); sendQueue.Clear(); } //发送用户数据 while (m_userQueue.Count > 0 && m_conn.Connected) { var data = m_userQueue.ToArray(); sendStream.Write(data, 0, data.Length); sendStream.Flush(); m_userQueue.Clear(); } //休眠100ms(文件输出时20ms) System.Threading.Thread.Sleep(IsPrinting?10:100); //检测终止标志(不确定) if (m_conn != null && m_conn.Client.Poll(1, SelectMode.SelectRead) && m_conn.Client.Available == 0) { this.Disconnect(); Logger.Info("Telnet 连接关闭(收到服务端指令)"); } } })).Start(); //绑定控件 //绑定用户输入事件 Screen.KeyPress += new System.Windows.Forms.KeyPressEventHandler(delegate(object sender, System.Windows.Forms.KeyPressEventArgs e) { m_userQueue.Push(Convert.ToByte(e.KeyChar)); }); Screen.KeyDown += new System.Windows.Forms.KeyEventHandler(delegate(object sender, System.Windows.Forms.KeyEventArgs e) { SendKey(e.KeyCode); //Console.WriteLine(e.KeyCode); }); //绑定用户输入事件 }