/// <param name="input">input stream /// </param> /// <param name="default_encoding">default encoding. null or "" => system default /// </param> /// <param name="alwaysConsumeBOM">If true, then consume the UTF-16 BOM. /// If false use the previous behavior that consumes /// a UTF-8 BOM but not a UTF-16 BOM. /// This flag is useful when reading a file into /// a string that is then passed to a parser. The parser may /// not know to strip out the BOM. /// </param> /// <returns> file encoding.. /// </returns> /// <throws> IOException </throws> public static String consumeBOM(Stream input, String default_encoding, bool alwaysConsumeBOM) { long markPosition = input.Position; // Determine file encoding... // ASCII - no header (use the supplied encoding) // UTF8 - EF BB BF // UTF16 - FF FE or FE FF (decoder chooses endian-ness) if (input.ReadByte() == 0xef && input.ReadByte() == 0xbb && input.ReadByte() == 0xbf) { // UTF-8 reader does not consume BOM, so do not reset if (SystemProperties.getProperty("flex.platform.CLR") != null) { return("UTF8"); } else { return("UTF-8"); } } else { input.Position = markPosition; int b0 = input.ReadByte(); int b1 = input.ReadByte(); if (b0 == 0xff && b1 == 0xfe || b0 == 0xfe && b1 == 0xff) { // If we don't consume the BOM is its assumed a // UTF-16 reader will consume BOM if (!alwaysConsumeBOM) { input.Position = markPosition; } if (SystemProperties.getProperty("flex.platform.CLR") != null) { return("UTF16"); } else { return("UTF-16"); } } else { // no BOM found input.Position = markPosition; if (default_encoding != null && default_encoding.Length != 0) { return(default_encoding); } else { return(SystemProperties.getProperty("file.encoding")); } } } }
public static bool useCompression(int version) { if ((SystemProperties.getProperty("flex.swf.uncompressed") != null)) { return(false); } return(version >= 6); }
static Trace() { { try { stackLines = Int32.Parse(SystemProperties.getProperty("trace.stackLines")); } catch (FormatException) { } catch (ArgumentNullException) { } } }
/// <summary> See if this document starts with a BOM and try to figure /// out an encoding from it. /// </summary> /// <param name="bis">for document (so that we can reset the stream /// if we establish that the first characters aren't a BOM) /// </param> /// <returns> CharSet from BOM (or system default / null) /// </returns> private Encoding getEncodingFromBOM(BufferedStream bis) { Encoding bomEncoding = null; //SupportClass.BufferedStreamManager.manager.MarkPosition(3, bis); String bomEncodingString; try { bomEncodingString = FileUtils.consumeBOM(bis, null); } catch (IOException) { bomEncodingString = SystemProperties.getProperty("file.encoding"); //$NON-NLS-1$ } bomEncoding = Encoding.GetEncoding(bomEncodingString); return(bomEncoding); }
} //$NON-NLS-1$ public static void appendVariableValue(System.Text.StringBuilder sb, Value val, String variableName) { int type = val.getType(); String typeName = val.getTypeName(); String className = val.getClassName(); // if no string or empty then typeName is blank if (typeName != null && typeName.Length == 0) { typeName = null; } switch (type) { case VariableType.NUMBER: { double value = ((Double)val.ValueAsObject); long longValue = (long)value; // The value is stored as a double; however, in practice most values are // actually integers. Check to see if this is the case, and if it is, // then display it: // - without a fraction, and // - with its hex equivalent in parentheses. // Note, we use 'long' instead of 'int', in order to deal with the // ActionScript type 'uint'. if (longValue == value) { sb.Append(longValue); sb.Append(" (0x"); //$NON-NLS-1$ sb.Append(Convert.ToString(longValue, 16)); sb.Append(")"); //$NON-NLS-1$ } else { sb.Append(value); } break; } case VariableType.BOOLEAN: { Boolean b = (Boolean)val.ValueAsObject; if (b) { sb.Append("true"); } //$NON-NLS-1$ else { sb.Append("false"); //$NON-NLS-1$ } break; } case VariableType.STRING: { bool isException = (val.isAttributeSet(ValueAttribute.IS_EXCEPTION)); sb.Append(isException?'<':'\"'); sb.Append(val.ValueAsString); sb.Append(isException?'>':'\"'); break; } case VariableType.OBJECT: { sb.Append("["); //$NON-NLS-1$ sb.Append(className); // Normally, we include the object id after the class name. // However, when running fdbunit, don't show object IDs, so that // results can reproduce consistently from one run to the next. if (SystemProperties.getProperty("fdbunit") == null) //$NON-NLS-1$ { sb.Append(" "); //$NON-NLS-1$ sb.Append(val.ValueAsObject); // object id } if (typeName != null && !typeName.Equals(className)) { sb.Append(", class='"); //$NON-NLS-1$ // Often the typename is of the form 'classname@hexaddress', // but the hex address is the same as the object id which // is returned by getValue() -- we don't want to display it // here. int at = typeName.IndexOf('@'); if (at != -1) { typeName = typeName.Substring(0, (at) - (0)); } sb.Append(typeName); sb.Append('\''); } sb.Append(']'); break; } case VariableType.FUNCTION: { // here we have a special case for getters/setters which // look like functions to us, except the attribute is set. sb.Append('['); if (val.isAttributeSet(VariableAttribute.HAS_GETTER)) { sb.Append(LocalizationManager.getLocalizedTextString("getterFunction")); } //$NON-NLS-1$ else if (val.isAttributeSet(VariableAttribute.HAS_SETTER)) { sb.Append(LocalizationManager.getLocalizedTextString("setterFunction")); } //$NON-NLS-1$ else { sb.Append(LocalizationManager.getLocalizedTextString("function")); //$NON-NLS-1$ } sb.Append(' '); sb.Append(val.ValueAsObject); if (typeName != null && !typeName.Equals(variableName)) { sb.Append(", name='"); //$NON-NLS-1$ sb.Append(typeName); sb.Append('\''); } sb.Append(']'); break; } case VariableType.MOVIECLIP: { sb.Append("["); //$NON-NLS-1$ sb.Append(className); sb.Append(" "); //$NON-NLS-1$ sb.Append(val.ValueAsObject); if (typeName != null && !typeName.Equals(className)) { sb.Append(", named='"); //$NON-NLS-1$ sb.Append(typeName); sb.Append('\''); } sb.Append(']'); break; } case VariableType.NULL: { sb.Append("null"); //$NON-NLS-1$ break; } case VariableType.UNDEFINED: { sb.Append("undefined"); //$NON-NLS-1$ break; } case VariableType.UNKNOWN: { sb.Append(LocalizationManager.getLocalizedTextString("unknownVariableType")); //$NON-NLS-1$ break; } } }