static private NewString ( byte bytes ) : string | ||
bytes | byte | |
return | string |
/// <summary> /// Writes the Manifest to the specified OutputStream. /// Attributes.Name.MANIFEST_VERSION must be set in /// MainAttributes prior to invoking this method. /// </summary> /// <param name="out"> the output stream </param> /// <exception cref="IOException"> if an I/O error has occurred </exception> /// <seealso cref= #getMainAttributes </seealso> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void write(java.io.OutputStream out) throws java.io.IOException public virtual void Write(OutputStream @out) { DataOutputStream dos = new DataOutputStream(@out); // Write out the main attributes for the manifest Attr.WriteMain(dos); // Now write out the pre-entry attributes IEnumerator <java.util.Map_Entry <String, Attributes> > it = Entries_Renamed.GetEnumerator(); while (it.MoveNext()) { java.util.Map_Entry <String, Attributes> e = it.Current; StringBuffer buffer = new StringBuffer("Name: "); String value = e.Key; if (value != null) { sbyte[] vb = value.GetBytes("UTF8"); value = StringHelperClass.NewString(vb, 0, 0, vb.Length); } buffer.Append(value); buffer.Append("\r\n"); Make72Safe(buffer); dos.WriteBytes(buffer.ToString()); e.Value.Write(dos); } dos.Flush(); }
public override void onReceive(int channelId, sbyte[] data) { if (outerInstance.mConnectionHandler == null) { return; } DateTime calendar = new GregorianCalendar(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd aa hh:mm:ss.SSS"); string timeStr = " " + dateFormat.format(calendar); string strToUpdateUI = StringHelperClass.NewString(data); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String message = strToUpdateUI.concat(timeStr); string message = strToUpdateUI + timeStr; new Thread(() => { try { outerInstance.mConnectionHandler.secureSend(SECURED_CHANNEL_ID, message.GetBytes()); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } }).start(); }
private static JObject GetParams(Stream inputStream) { byte[] buffer = StreamToBytes(inputStream); var bodyData = StringHelperClass.NewString(buffer.ToArray(), "UTF-8"); if (bodyData.Length > 0 && bodyData[0] != '{' && bodyData[0] != '<') { var resultObject = new JObject(); var paramList = bodyData.Split('&'); foreach (var item in paramList) { var nameValue = item.Split('='); if (nameValue.Length == 2) { resultObject[nameValue[0]] = string.IsNullOrEmpty(nameValue[1]) ? null : HttpUtility.UrlDecode(nameValue[1]); } } return(resultObject); } try { return(inputStream.Length == 0 ? JObject.Parse("{}") : JObject.Parse(bodyData)); } catch (Exception) { XmlDocument doc = new XmlDocument(); doc.LoadXml(bodyData); var jsonString = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc); return(inputStream.Length == 0 ? JObject.Parse("{}") : JObject.Parse(jsonString)); } }
public override void onReceive(int channelId, sbyte[] data) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String message = new String(data); string message = StringHelperClass.NewString(data); outerInstance.addMessage("Received: ", message); }
static ConcurrentDeploymentTest() { IBpmnModelInstance modelInstance = ESS.FW.Bpm.Model.Bpmn.Bpmn.CreateExecutableProcess().StartEvent().Done(); System.IO.MemoryStream outputStream = new System.IO.MemoryStream(); ESS.FW.Bpm.Model.Bpmn.Bpmn.WriteModelToStream(outputStream, modelInstance); processResource = StringHelperClass.NewString(outputStream.ToArray()); }
public override void onReceive(int channelId, sbyte[] data) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String strToUpdateUI = new String(data); string strToUpdateUI = StringHelperClass.NewString(data); outerInstance.onDataAvailableonChannel(this, channelId, strToUpdateUI); }
private string ReadPassword(int length) { sbyte[] ASCIIPassword = new sbyte[length - 1]; chipDat.ReadFully(ASCIIPassword); for (int i = 0; i < ASCIIPassword.Length; i++) { ASCIIPassword[i] ^= unchecked ((sbyte)0x99); } string password = StringHelperClass.NewString(ASCIIPassword, "ASCII"); return(password); }
public override void onReceive(int channelId, sbyte[] data) { try { Log.i(TAG, "onReceive: channelId" + channelId + "data: " + StringHelperClass.NewString(data, "UTF-8")); } catch (UnsupportedEncodingException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } }
// -------------------------------------------------------- // encoding // -------------------------------------------------------- /// <summary> /// Base64-encode the given data and return a newly allocated /// String with the result. /// </summary> /// <param name="input"> the data to encode </param> /// <param name="offset"> the position within the input array at which to /// start </param> /// <param name="len"> the number of bytes of input to encode </param> /// <param name="flags"> controls certain features of the encoded output. /// Passing {@code DEFAULT} results in output that /// adheres to RFC 2045. </param> public static string encodeToString(byte[] input, int offset, int len, int flags) { try { return(StringHelperClass.NewString(encode(input, offset, len, flags), "US-ASCII")); } catch (Exception e) { // US-ASCII is guaranteed to be available. throw e; } }
/// <summary> /// Parse a camunda:resource attribute and loads the resource depending on the url scheme. /// Supported Uri schemes are <code>classpath://</code> and <code>deployment://</code>. /// If the scheme is omitted <code>classpath://</code> is assumed. /// </summary> /// <param name="resourcePath"> the path to the resource to load </param> /// <param name="deployment"> the deployment to load resources from </param> /// <returns> the resource content as <seealso cref="string" /> </returns> public static string LoadResourceContent(string resourcePath, DeploymentEntity deployment) { var pathSplit = resourcePath.Split("://", true); string resourceType; if (pathSplit.Length == 1) { resourceType = "classpath"; } else { resourceType = pathSplit[0]; } var resourceLocation = pathSplit[pathSplit.Length - 1]; byte[] resourceBytes = null; if (resourceType.Equals("classpath")) { Stream resourceAsStream = null; try { resourceAsStream = ReflectUtil.GetResourceAsStream(resourceLocation); if (resourceAsStream != null) { resourceBytes = IoUtil.ReadInputStream(resourceAsStream, resourcePath); } } finally { IoUtil.CloseSilently(resourceAsStream); } } else if (resourceType.Equals("deployment")) { ResourceEntity resourceEntity = deployment.GetResource(resourceLocation); if (resourceEntity != null) { resourceBytes = resourceEntity.Bytes; } } if (resourceBytes != null) { return(StringHelperClass.NewString(resourceBytes, Encoding.UTF8.ToString())); } throw Log.CannotFindResource(resourcePath); }
private String ParseName(sbyte[] lbuf, int len) { if (ToLower(lbuf[0]) == 'n' && ToLower(lbuf[1]) == 'a' && ToLower(lbuf[2]) == 'm' && ToLower(lbuf[3]) == 'e' && lbuf[4] == ':' && lbuf[5] == ' ') { try { return(StringHelperClass.NewString(lbuf, 6, len - 6, "UTF8")); } catch (Exception) { } } return(null); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: @Override public void directIOOccurred(final jpos.events.DirectIOEvent e) public override void directIOOccurred(DirectIOEvent e) { Activity.runOnUiThread(() => { deviceMessagesTextView.append("DirectIO: " + e + "(" + getBatterStatusString(e.Data) + ")\n"); if (e.Object != null) { deviceMessagesTextView.append(StringHelperClass.NewString((sbyte[])e.Object) + "\n"); } scroll(); }); }
/// <summary> /// Constructs a new <code>String</code> by decoding the specified array of bytes using the given charset. /// <para> /// This method catches <seealso cref="UnsupportedEncodingException" /> and re-throws it as /// <seealso cref="IllegalStateException" />, which /// should never happen for a required charset name. Use this method when the encoding is required to be in the /// JRE. /// </para> /// </summary> /// <param name="bytes"> /// The bytes to be decoded into characters /// </param> /// <param name="charsetName"> /// The name of a required <seealso cref="Encoding" /> /// </param> /// <returns> A new <code>String</code> decoded from the specified array of bytes using the given charset. </returns> /// <exception cref="IllegalStateException"> /// Thrown when a <seealso cref="UnsupportedEncodingException" /> is caught, which should never happen for a /// required charset name. /// </exception> /// <seealso cref= /// <a href="http://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/CharEncoding.html">CharEncoding</a> /// </seealso> /// <seealso cref= String# String( byte[], String /// ) /// </seealso> public static string NewString(byte[] bytes, string charsetName) { if (bytes == null) { return(null); } try { return(StringHelperClass.NewString(bytes, charsetName)); } catch (System.Exception e) { throw NewIllegalStateException(charsetName, e); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private String toString(java.io.InputStream is) throws java.io.IOException private string ToString(System.IO.Stream @is) { StringBuilder sb = new StringBuilder(); sbyte[] buff = new sbyte[1024]; while (true) { int r = @is.Read(buff, 0, buff.Length); if (r == -1) { break; } sb.Append(StringHelperClass.NewString(buff, 0, r)); } return(sb.ToString()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processMultiPart(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException private void processMultiPart(HttpServletRequest req, HttpServletResponse resp) { PrintWriter @out = resp.Writer; resp.ContentType = "text/plain"; MultipartParser mp = new MultipartParser(req, 2048); Part part = null; while ((part = mp.readNextPart()) != null) { string name = part.Name.Trim(); if (part.Param) { // it's a parameter part ParamPart paramPart = (ParamPart)part; string value = paramPart.StringValue.Trim(); LOG.info("param; name=" + name + ", value=" + value); @out.print("param; name=" + name + ", value=" + value); } else if (part.File) { // it's a file part FilePart filePart = (FilePart)part; string fileName = filePart.FileName; if (!string.ReferenceEquals(fileName, null)) { // the part actually contained a file // StringWriter sw = new StringWriter(); // long size = filePart.writeTo(new File(System // .getProperty("java.io.tmpdir"))); System.IO.MemoryStream baos = new System.IO.MemoryStream(); long size = filePart.writeTo(baos); LOG.info("file; name=" + name + "; filename=" + fileName + ", filePath=" + filePart.FilePath + ", content type=" + filePart.ContentType + ", size=" + size); @out.print(string.Format("{0}: {1}", name, (StringHelperClass.NewString(baos.toByteArray())).Trim())); } else { // the field did not contain a file LOG.info("file; name=" + name + "; EMPTY"); } @out.flush(); } } resp.Status = HttpServletResponse.SC_OK; }
public static void Main(string[] args) { int i; int RFS = RSA.RFS; string message = "Hello World\n"; rsa_public_key pub = new rsa_public_key(ROM.FFLEN); rsa_private_key priv = new rsa_private_key(ROM.HFLEN); sbyte[] ML = new sbyte[RFS]; sbyte[] C = new sbyte[RFS]; sbyte[] RAW = new sbyte[100]; RAND rng = new RAND(); rng.clean(); for (i = 0; i < 100; i++) { RAW[i] = (sbyte)(i); } rng.seed(100, RAW); //for (i=0;i<10;i++) //{ Console.WriteLine("Generating public/private key pair"); RSA.KEY_PAIR(rng, 65537, priv, pub); sbyte[] M = message.GetBytes(); Console.Write("Encrypting test string\n"); sbyte[] E = RSA.OAEP_ENCODE(M, rng, null); // OAEP encode message M to E RSA.ENCRYPT(pub, E, C); // encrypt encoded message Console.Write("Ciphertext= 0x"); RSA.printBinary(C); Console.Write("Decrypting test string\n"); RSA.DECRYPT(priv, C, ML); sbyte[] MS = RSA.OAEP_DECODE(null, ML); // OAEP decode message message = StringHelperClass.NewString(MS); Console.Write(message); //} RSA.PRIVATE_KEY_KILL(priv); }
/* * Writes the current attributes to the specified data output stream, * make sure to write out the MANIFEST_VERSION or SIGNATURE_VERSION * attributes first. * * XXX Need to handle UTF8 values and break up lines longer than 72 bytes */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: void writeMain(java.io.DataOutputStream out) throws java.io.IOException internal virtual void WriteMain(DataOutputStream @out) { // write out the *-Version header first, if it exists String vername = Name.MANIFEST_VERSION.ToString(); String version = GetValue(vername); if (version == java.util.Map_Fields.Null) { vername = Name.SIGNATURE_VERSION.ToString(); version = GetValue(vername); } if (version != java.util.Map_Fields.Null) { @out.WriteBytes(vername + ": " + version + "\r\n"); } // write out all attributes except for the version // we wrote out earlier IEnumerator <java.util.Map_Entry <Object, Object> > it = EntrySet().Iterator(); while (it.MoveNext()) { java.util.Map_Entry <Object, Object> e = it.Current; String name = ((Name)e.Key).ToString(); if ((version != java.util.Map_Fields.Null) && !(name.EqualsIgnoreCase(vername))) { StringBuffer buffer = new StringBuffer(name); buffer.Append(": "); String value = (String)e.Value; if (value != java.util.Map_Fields.Null) { sbyte[] vb = value.GetBytes("UTF8"); value = StringHelperClass.NewString(vb, 0, 0, vb.Length); } buffer.Append(value); buffer.Append("\r\n"); Manifest.Make72Safe(buffer); @out.WriteBytes(buffer.ToString()); } } @out.WriteBytes("\r\n"); }
protected void Button1_Click(object sender, EventArgs e) { try { sbyte[] encr = AESImplementation.encrypt(this.txtPlainText.Text.GetBytes(), this.txtPrivateKey.Text.GetBytes()); this.txtEncryptText.Text = string.Join(" ", encr); sbyte[] decr = AESImplementation.decrypt(encr, this.txtPrivateKey.Text.GetBytes()); this.txtDecryptText.Text = string.Join(" ", StringHelperClass.NewString(decr)); this.txtAesLog.Text = string.Join("\n", FileHelper.FileContent); FileHelper.FileContent.Clear(); } catch (Exception) { throw; } }
public static String Get(int cp) { sbyte[] strPool = null; if (RefStrPool == null || (strPool = RefStrPool.get()) == null) { strPool = InitNamePool(); } int off = 0; if (Lookup[cp >> 8] == null || (off = Lookup[cp >> 8][cp & 0xff]) == 0) { return(null); } //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("deprecation") String result = new String(strPool, 0, off >>> 8, off & 0xff); String result = StringHelperClass.NewString(strPool, 0, (int)((uint)off >> 8), off & 0xff); // ASCII return(result); }
/// <summary> /// The object implements the readExternal method to restore its /// contents by calling the methods of DataInput for primitive /// types and readObject for objects, strings and arrays. The /// readExternal method must read the values in the same sequence /// and with the same types as were written by writeExternal. </summary> /// <exception cref="ClassNotFoundException"> If the class for an object being /// restored cannot be found. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void readExternal(java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException public virtual void ReadExternal(ObjectInput @in) { String s = @in.ReadUTF(); if (s == null || s.Length() == 0) // long mime type { sbyte[] ba = new sbyte[@in.ReadInt()]; @in.ReadFully(ba); s = StringHelperClass.NewString(ba); } try { Parse(s); } catch (MimeTypeParseException e) { throw new IOException(e.ToString()); } }
static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; try { string input = "Hello, my name is John Woo"; string key = "1a25s8fe5dsg65ad"; Console.WriteLine("Входен текс: " + input); sbyte[] encr = AESImplementation.encrypt(input.GetBytes(), key.GetBytes()); Console.WriteLine("Криптиран текст със AES: " + StringHelperClass.NewString(encr)); sbyte[] decr = AESImplementation.decrypt(encr, key.GetBytes()); Console.WriteLine("Декриптиран текст със AES: " + StringHelperClass.NewString(decr)); FileHelper.SaveToFile(); } catch (Exception) { throw; } }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public static String toStringFromAscii(final byte[] bytes) public static string toStringFromAscii(sbyte[] bytes) { sbyte[] ret = new sbyte[bytes.Length]; for (int x = 0; x < bytes.Length; x++) { if (bytes[x] < 32 && bytes[x] >= 0) { ret[x] = 46; } else { ret[x] = bytes[x]; } } try { return(StringHelperClass.NewString(ret, "GB18030")); } catch { return(""); } }
public override void onClick(View v) { string data = dataEditText.Text.ToString(); int symbology = Symbology; try { int height = 0; if (heightEditText.Enabled) { height = Convert.ToInt32(heightEditText.Text.ToString()); } int width = 0; if (widthEditText.Enabled) { width = Convert.ToInt32(widthEditText.Text.ToString()); } int alignment = Alignment; int textPosition = TextPosition; if (symbology == POSPrinterConst.PTR_BCS_MAXICODE) { string dummyHeader = StringHelperClass.NewString(new sbyte[] { (sbyte)'[', (sbyte)')', (sbyte)'>', 0x1e, (sbyte)'0', (sbyte)'1', 0x1d, (sbyte)'9', (sbyte)'6', (sbyte)'1', (sbyte)'2', (sbyte)'3', (sbyte)'4', (sbyte)'5', (sbyte)'6', (sbyte)'7', (sbyte)'8', (sbyte)'9', 0x1d, (sbyte)'0', (sbyte)'0', (sbyte)'7', 0x1d, (sbyte)'2', (sbyte)'5', (sbyte)'0', 0x1d }); data = dummyHeader + data; } posPrinter.printBarCode(POSPrinterConst.PTR_S_RECEIPT, data, symbology, height, width, alignment, textPosition); } //JAVA TO C# CONVERTER TODO TASK: There is no equivalent in C# to Java 'multi-catch' syntax: catch (NumberFormatException | JposException e) { e.printStackTrace(); MessageDialogFragment.showDialog(FragmentManager, "Exception", e.Message); } }
public virtual string signRequest(Uri url, string method, byte[] body, string contentType) { StringBuilder sb = new StringBuilder(); // <Method> <Path><?Query> string line = string.Format("{0} {1}", method, url.LocalPath); sb.Append(line); if (url.Query != "") { sb.Append(url.Query); } // Host: <Host> sb.Append(string.Format("\nHost: {0}", url.Host)); if (url.Port != 80) { sb.Append(string.Format(":{0}", url.Port)); } // Content-Type: <Content-Type> if (contentType != null) { sb.Append(string.Format("\nContent-Type: {0}", contentType)); } // body sb.Append("\n\n"); if (body != null && contentType != null && !"application/octet-stream".Equals(contentType)) { sb.Append(StringHelperClass.NewString(body)); } return(string.Format("{0} {1}:{2}", DIGEST_AUTH_PREFIX, mAccessKey, signData(sb.ToString()))); }
/* * Writes the current attributes to the specified data output stream. * XXX Need to handle UTF8 values and break up lines longer than 72 bytes */ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: void write(java.io.DataOutputStream os) throws java.io.IOException internal virtual void Write(DataOutputStream os) { IEnumerator <java.util.Map_Entry <Object, Object> > it = EntrySet().Iterator(); while (it.MoveNext()) { java.util.Map_Entry <Object, Object> e = it.Current; StringBuffer buffer = new StringBuffer(((Name)e.Key).ToString()); buffer.Append(": "); String value = (String)e.Value; if (value != java.util.Map_Fields.Null) { sbyte[] vb = value.GetBytes("UTF8"); value = StringHelperClass.NewString(vb, 0, 0, vb.Length); } buffer.Append(value); buffer.Append("\r\n"); Manifest.Make72Safe(buffer); os.WriteBytes(buffer.ToString()); } os.WriteBytes("\r\n"); }
private void LoadAllFolders() { MFolders = new SparseArray <FolderModel>(); string[] folders = FileList(); foreach (string folderFileName in folders) { System.IO.FileStream @in = null; try { if (folderFileName.StartsWith("folder", StringComparison.Ordinal)) { FolderModel folder = new FolderModel(); folder.Id = int.Parse(folderFileName.Substring("folder".Length)); @in = (System.IO.FileStream)OpenFileInput(folderFileName); System.IO.MemoryStream bos = new System.IO.MemoryStream(); byte[] b = new byte[1024]; int bytesRead; while ((bytesRead = @in.Read(b, 0, b.Length)) != -1) { bos.Write(b, 0, bytesRead); } byte[] bytes = bos.ToArray(); string appNames = StringHelperClass.NewString((sbyte[])(Array)bytes); int i = 0; foreach (string appName in appNames.Split("\n", true)) { if (i < 2) { // width and height try { if (i == 0) { folder.Width = int.Parse(appName); } else if (i == 1) { folder.Height = int.Parse(appName); } } catch (System.FormatException) { string msg = "Please uninstall Floating Folders and reinstall it. The folder format has changed."; Log.Debug("FloatingFolder", msg); Toast.MakeText(this, msg, ToastLength.Short).Show(); break; } i++; } else { if (appName.Length > 0) { ComponentName name = ComponentName.UnflattenFromString(appName); try { ActivityInfo app = MPackageManager.GetActivityInfo(name, 0); folder.Apps.Add(app); MFolders.Put(folder.Id, folder); } catch (PackageManager.NameNotFoundException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } } } } } } catch (FileNotFoundException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } catch (IOException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } finally { if (@in != null) { try { @in.Close(); } catch (IOException e) { System.Console.WriteLine(e.ToString()); System.Console.Write(e.StackTrace); } } } } }
public virtual string DecryptPassword(byte[] storedPassword, string userPassword) { // TODO return(StringHelperClass.NewString(storedPassword)); }
public override GameLevel GetLevel(int n) { if (n < 1 || n > levelCount) { throw new ArgumentException("Level outside of range"); } GameLevel gameLevel = null; try { int offset = GetLevelOffset(n); chipDat.Seek(offset); int numBytesLevel = chipDat.ReadUnsignedWord(); // So we don't have to skip over the same level again later levelOffsets[n + 1] = offset + numBytesLevel + 2; int levelNumber = chipDat.ReadUnsignedWord(); int numSeconds = chipDat.ReadUnsignedWord(); int numChipsNeeded = chipDat.ReadUnsignedWord(); int mapDetail = chipDat.ReadUnsignedWord(); gameLevel = new GameLevel(32, 32, numChipsNeeded, numSeconds, levelNumber); int numberOfBytesLayer1 = chipDat.ReadUnsignedWord(); ReadLayer(gameLevel, numberOfBytesLayer1, 1); // Layer 1, upper int numberOfBytesLayer2 = chipDat.ReadUnsignedWord(); ReadLayer(gameLevel, numberOfBytesLayer2, 0); // Layer 2, lower int numBytesOptional = chipDat.ReadUnsignedWord(); int numOptionalBytesRead = 0; while (numOptionalBytesRead < numBytesOptional) { int fieldType = chipDat.ReadUnsignedByte(); int sizeOfField = chipDat.ReadUnsignedByte(); numOptionalBytesRead += 2; switch (fieldType) { case 0x03: // Map title sbyte[] ASCIITitle = new sbyte[sizeOfField - 1]; chipDat.ReadFully(ASCIITitle); string title = StringHelperClass.NewString(ASCIITitle, "ASCII"); gameLevel.MapTitle = title; chipDat.SkipBytes(1); break; case 0x04: // Brown buttons to traps for (int i = 0; i < sizeOfField / 10; i++) { int buttonX = chipDat.ReadUnsignedWord(); int buttonY = chipDat.ReadUnsignedWord(); int trapX = chipDat.ReadUnsignedWord(); int trapY = chipDat.ReadUnsignedWord(); // Locate button BlockContainer bc = gameLevel.GetBlockContainer(buttonX, buttonY); Block button = bc.Find(Type.BROWNBUTTON); // Locate trap bc = gameLevel.GetBlockContainer(trapX, trapY); Block trap = bc.Find(Type.TRAP); if (button != null && trap != null) // Perhaps throw an exception otherwise { Buttons.AddBrownButtonListener(button, trap); } chipDat.SkipBytes(2); } break; case 0x05: for (int i = 0; i < sizeOfField / 8; i++) { int buttonX = chipDat.ReadUnsignedWord(); int buttonY = chipDat.ReadUnsignedWord(); int clonerX = chipDat.ReadUnsignedWord(); int clonerY = chipDat.ReadUnsignedWord(); // Locate button BlockContainer bc = gameLevel.GetBlockContainer(buttonX, buttonY); Block button = bc.Find(Type.REDBUTTON); // Locate cloner bc = gameLevel.GetBlockContainer(clonerX, clonerY); Block cloner = bc.Find(Type.CLONEMACHINE); if (button != null && cloner != null) // Perhaps throw an exception otherwise { Buttons.AddRedButtonListener(button, cloner); } } break; case 0x06: // Password string password = ReadPassword(sizeOfField); gameLevel.Password = password; passwordToLevel[password] = n; levelToPassword[n] = password; chipDat.SkipBytes(1); break; case 0x07: // Hint sbyte[] ASCIIHint = new sbyte[sizeOfField - 1]; chipDat.ReadFully(ASCIIHint); string hint = StringHelperClass.NewString(ASCIIHint, "ASCII"); gameLevel.Hint = hint; chipDat.SkipBytes(1); break; case 0x0A: // Movement for (int i = 0; i < sizeOfField / 2; i++) { int creatureX = chipDat.ReadUnsignedByte(); int creatureY = chipDat.ReadUnsignedByte(); Block creature = null; BlockContainer bc; Block upper; // Locate creature bc = gameLevel.GetBlockContainer(creatureX, creatureY); upper = bc.Upper; if (upper.Creature) { creature = upper; } if (creature != null) // Perhaps throw an exception otherwise { Creatures.AddCreature(creature); } } break; default: chipDat.SkipBytes(sizeOfField); break; } numOptionalBytesRead += sizeOfField; } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); Debug.Write(ex.StackTrace); Debug.WriteLine("While loading level: " + ex.Message); } return(gameLevel); }
public override void send(sbyte[] bytes) { sb.Append(StringHelperClass.NewString(bytes)); }
/// <summary> /// Returns the input stream as <seealso cref="string" />. /// </summary> /// <param name="inputStream"> the input stream </param> /// <returns> the input stream as <seealso cref="string" />. </returns> public static string InputStreamAsString(Stream inputStream) { return(StringHelperClass.NewString(InputStreamAsByteArray(inputStream), EncodingCharset)); }