/// <summary> /// Obtém logotipo do repositório /// </summary> /// <returns>Imagem contendo logotipo</returns> private static Image ObterLogotipoOriginal() { Image logotipo; System.IO.BufferedStream buffer = new System.IO.BufferedStream( Assembly.GetExecutingAssembly().GetManifestResourceStream("Apresentação.Mercadoria.Etiqueta.Impressão.Layout.Logo.jpg")); logotipo = Image.FromStream(buffer); buffer.Close(); return logotipo; }
/// <summary> /// Salva todos os relatórios em um único PDF. /// </summary> /// <param name="p_filename">Nome do arquivo PDF a ser salvo.</param> public void SaveMerged(string p_filename) { PDFjet.NET.PDF v_pdf; System.IO.BufferedStream v_buffer; System.IO.FileStream f; Spartacus.Reporting.Report v_report; double v_perc, v_percstep, v_lastperc; try { f = new System.IO.FileStream(p_filename, System.IO.FileMode.Create); v_buffer = new System.IO.BufferedStream(f); v_pdf = new PDFjet.NET.PDF(v_buffer); v_perc = 0.0; v_percstep = 100.0 / (double)this.v_reports.Count; v_lastperc = v_percstep; for (int k = 0; k < this.v_reports.Count; k++) { v_report = this.v_reports[k]; v_report.v_perc = v_perc; v_report.v_percstep = v_percstep; v_report.v_lastperc = v_lastperc; v_report.SavePartial(v_pdf); v_perc = v_lastperc; v_lastperc += v_percstep; } v_pdf.Flush(); v_buffer.Close(); } catch (Spartacus.Reporting.Exception e) { throw e; } catch (System.Exception e) { throw new Spartacus.Reporting.Exception("Erro ao gerar o pacote PDF de saída.", e); } }
// 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> /// Salva como PDF. /// </summary> /// <param name="p_filename">Nome do arquivo PDF.</param> public void Save(string p_filename) { PDFjet.NET.PDF v_pdf; System.IO.BufferedStream v_buffer; System.IO.FileStream f; PDFjet.NET.Table v_dataheadertable = null, v_datatable; float[] v_layout; PDFjet.NET.Page v_page; System.Collections.Generic.List<System.Collections.Generic.List<PDFjet.NET.Cell>> v_rendered; int v_numpages, v_currentpage; Spartacus.Utils.Cryptor v_cryptor; string v_datafilename; System.IO.StreamReader v_reader; // se o relatório não tiver dados, não faz nada if (this.v_table.Rows.Count == 0) return; try { this.v_progress.FireEvent("Spartacus.Reporting.Report", "ExportPDF", this.v_perc, "Renderizando relatorio " + this.v_reportid.ToString() + " no arquivo " + p_filename); this.v_inc = this.v_percstep / (double) this.v_table.Rows.Count; this.v_renderedrows = 0; f = new System.IO.FileStream(p_filename, System.IO.FileMode.Create); v_buffer = new System.IO.BufferedStream(f); v_pdf = new PDFjet.NET.PDF(v_buffer); if (this.v_settings.v_layout == Spartacus.Reporting.PageLayout.LANDSCAPE) v_layout = PDFjet.NET.A4.LANDSCAPE; else v_layout = PDFjet.NET.A4.PORTRAIT; v_page = new PDFjet.NET.Page(v_pdf, v_layout); // tabela de cabecalho de dados if (this.v_settings.v_showdataheader) { v_dataheadertable = new PDFjet.NET.Table(); v_dataheadertable.SetPosition(this.v_settings.v_leftmargin, this.v_settings.v_topmargin + this.v_header.v_height); v_rendered = this.RenderDataHeader( v_page.GetHeight(), v_page.GetWidth(), this.v_settings.v_dataheaderfont.GetFont(v_pdf) ); v_dataheadertable.SetData(v_rendered, PDFjet.NET.Table.DATA_HAS_0_HEADER_ROWS); //v_dataheadertable.SetCellBordersWidth(1.5f); } // tabela de dados v_datatable = new PDFjet.NET.Table(); //v_datatable.SetPosition(this.v_settings.v_leftmargin, this.v_settings.v_topmargin + this.v_header.v_height + ((this.v_settings.v_dataheaderfont.v_size + 2) * 1.8 * this.v_numrowsdetail)); if (this.v_settings.v_showdataheader) v_datatable.SetPosition(this.v_settings.v_leftmargin, this.v_settings.v_topmargin + this.v_header.v_height + ((this.v_settings.v_dataheaderfont.v_size + 2) * 1.8 * this.v_numrowsdataheader)); else v_datatable.SetPosition(this.v_settings.v_leftmargin, this.v_settings.v_topmargin + this.v_header.v_height); v_datatable.SetBottomMargin(this.v_settings.v_bottommargin + this.v_footer.v_height); this.BuildTemplates( v_page.GetHeight(), v_page.GetWidth(), this.v_settings.v_datafieldfont.GetFont(v_pdf), this.v_settings.v_groupheaderfont.GetFont(v_pdf), this.v_settings.v_groupfooterfont.GetFont(v_pdf) ); v_cryptor = new Spartacus.Utils.Cryptor("spartacus"); v_datafilename = v_cryptor.RandomString() + ".tmp"; this.v_datafile = System.IO.File.Open( v_datafilename, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite ); v_rendered = this.RenderData( v_page.GetHeight(), v_page.GetWidth(), this.v_settings.v_datafieldfont.GetFont(v_pdf), this.v_settings.v_groupheaderfont.GetFont(v_pdf), this.v_settings.v_groupfooterfont.GetFont(v_pdf) ); v_datatable.SetData(v_rendered, PDFjet.NET.Table.DATA_HAS_0_HEADER_ROWS); //v_datatable.SetCellBordersWidth(1.5f); this.v_datafile.Seek(0, System.IO.SeekOrigin.Begin); v_reader = new System.IO.StreamReader(this.v_datafile); // salvando PDF this.v_header.SetValues(this.v_table); this.v_footer.SetValues(this.v_table); v_numpages = v_datatable.GetNumberOfPages(v_page); v_currentpage = 1; while (v_datatable.HasMoreData()) { this.v_header.SetPageNumber(v_currentpage, v_numpages); this.v_footer.SetPageNumber(v_currentpage, v_numpages); this.v_header.Render( this.v_settings.v_reportheaderfont, this.v_settings.v_leftmargin, this.v_settings.v_topmargin, this.v_settings.v_rightmargin, v_pdf, v_page ); if (this.v_settings.v_showdataheader) v_dataheadertable.DrawOn(v_page); v_datatable.ImprovedDrawOn(v_page, v_reader); this.v_footer.Render( this.v_settings.v_reportfooterfont, this.v_settings.v_leftmargin, v_page.GetHeight() - v_settings.v_bottommargin - v_footer.v_height, this.v_settings.v_rightmargin, v_pdf, v_page ); if (v_datatable.HasMoreData()) { if (this.v_settings.v_showdataheader) v_dataheadertable.ResetRenderedPagesCount(); v_page = new PDFjet.NET.Page(v_pdf, v_layout); v_currentpage++; } } v_pdf.Flush(); v_buffer.Close(); v_reader.Close(); this.v_datafile.Close(); (new System.IO.FileInfo(v_datafilename)).Delete(); this.v_perc = this.v_lastperc; this.v_progress.FireEvent("Spartacus.Reporting.Report", "ExportPDF", this.v_perc, "Relatorio " + this.v_reportid.ToString() + " renderizado no arquivo " + p_filename); } catch (System.Exception e) { throw new Spartacus.Reporting.Exception("Erro ao gerar o arquivo PDF de saída.", e); } }
/// <summary> /// Save configuration to a XML file /// </summary> /// <param name="filename">The full path filename to save configuration</param> public void SaveToXml(string filename) { System.IO.BufferedStream xmlStream = null; byte [] xmlData; const int bufferSize = 4096; XmlDocument doc; #region Create doc, loading default xml // Load default xml from resource xmlStream = new System.IO.BufferedStream( Assembly.GetExecutingAssembly().GetManifestResourceStream("Report.Layout.Complex.DefaultLabelLayout.xml"), bufferSize); xmlData = new byte[xmlStream.Length]; while (xmlStream.Position < xmlStream.Length) xmlStream.Read((byte[]) xmlData, (int) xmlStream.Position, (int) Math.Min(bufferSize, xmlStream.Length - xmlStream.Position)); xmlStream.Close(); string strDefaultXml = System.Text.Encoding.UTF8.GetString(xmlData); strDefaultXml = strDefaultXml.Substring(strDefaultXml.IndexOf('<')); doc = new XmlDocument(); doc.LoadXml(strDefaultXml); #endregion SaveToXml(doc, doc["LabelLayout"]["ItemLayout"]); doc.Save(filename); }
/// <summary> /// Salva todos os relatórios em um único PDF. /// </summary> /// <param name="p_filename">Nome do arquivo PDF a ser salvo.</param> public void SaveMerged(string p_filename) { PDFjet.NET.PDF v_pdf; System.IO.BufferedStream v_buffer; System.IO.FileStream f; Spartacus.Reporting.Report v_report; double v_perc, v_percstep, v_lastperc; try { f = new System.IO.FileStream(p_filename, System.IO.FileMode.Create); v_buffer = new System.IO.BufferedStream(f); v_pdf = new PDFjet.NET.PDF(v_buffer); v_perc = 0.0; v_percstep = 100.0 / (double) this.v_reports.Count; v_lastperc = v_percstep; for (int k = 0; k < this.v_reports.Count; k++) { v_report = (Spartacus.Reporting.Report) this.v_reports[k]; v_report.v_perc = v_perc; v_report.v_percstep = v_percstep; v_report.v_lastperc = v_lastperc; v_report.SavePartial(v_pdf); v_perc = v_lastperc; v_lastperc += v_percstep; } v_pdf.Flush(); v_buffer.Close(); } catch (Spartacus.Reporting.Exception e) { throw e; } catch (System.Exception e) { throw new Spartacus.Reporting.Exception("Erro ao gerar o pacote PDF de saída.", e); } }
public static void Main(System.String[] args) { System.String aspath = null; for (int i = 0; i < args.Length; i++) { if (args[i].Equals("-aspath")) { aspath = args[++i]; continue; } TagEncoder encoder = new TagEncoder(); //ConsoleOutputHandler tagHandler = new ConsoleOutputHandler(null, null); SwfxParser swfxParser = new SwfxParser(encoder, StringUtils.splitPath(aspath)); bool success = swfxParser.parse(args[i]); //, tagHandler); if (success) { System.String swfFileName = args[i].Substring(0, (args[i].LastIndexOf('.')) - (0)) + ".swf"; //UPGRADE_TODO: Constructor 'java.io.FileOutputStream.FileOutputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileOutputStreamFileOutputStream_javalangString'" System.IO.Stream out_Renamed = new System.IO.BufferedStream(new System.IO.FileStream(swfFileName, System.IO.FileMode.Create)); try { encoder.writeTo(out_Renamed); } finally { out_Renamed.Close(); } } else { System.Environment.Exit(1); } } }
public virtual bool parse(System.String path) { // parser property names //UPGRADE_NOTE: Final was removed from the declaration of 'JAXP_SCHEMA_LANGUAGE '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; //UPGRADE_NOTE: Final was removed from the declaration of 'JAXP_SCHEMA_SOURCE '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; //UPGRADE_NOTE: Final was removed from the declaration of 'W3C_XML_SCHEMA '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; this.docPath = path; //this.outputHandler = handler; //UPGRADE_TODO: Constructor 'java.io.FileInputStream.FileInputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileInputStreamFileInputStream_javalangString'" System.IO.Stream in_Renamed = new System.IO.BufferedStream(new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read)); XmlSAXDocumentManager parser; try { XmlSAXDocumentManager factory = XmlSAXDocumentManager.NewInstance(); factory.IsValidating = true; factory.NamespaceAllowed = true; try { parser = XmlSAXDocumentManager.CloneInstance(factory); //UPGRADE_TODO: Method 'javax.xml.parsers.SAXParser.setProperty' was converted to 'XmlSAXDocumentManager.setProperty' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersSAXParsersetProperty_javalangString_javalangObject'" parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); //UPGRADE_TODO: Method 'javax.xml.parsers.SAXParser.setProperty' was converted to 'XmlSAXDocumentManager.setProperty' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersSAXParsersetProperty_javalangString_javalangObject'" GetType(); //UPGRADE_TODO: Method 'java.lang.Class.getResource' was converted to 'System.Uri' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangClassgetResource_javalangString'" parser.setProperty(JAXP_SCHEMA_SOURCE, new XmlSourceSupport(new System.Uri(System.IO.Path.GetFullPath("swfx.xsd")).ToString())); } catch (System.Exception e) { if (e is ManagerNotRecognizedException) { // schema validation not supported... ignore factory.IsValidating = false; factory.NamespaceAllowed = true; parser = XmlSAXDocumentManager.CloneInstance(factory); } else if (e is System.IO.IOException) { throw (System.IO.IOException) e; } else { //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" if (e is System.Xml.XmlException) { //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" throw (System.Xml.XmlException) e; } else { SupportClass.WriteStackTrace(e, Console.Error); parser = null; } } } parser.parse(in_Renamed, this); return true; } //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" catch (System.Xml.XmlException e) { // errors will have been reported already //e.printStackTrace(); return false; } catch (System.Exception e) { //UPGRADE_ISSUE: Class 'javax.xml.parsers.ParserConfigurationException' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxxmlparsersParserConfigurationException'" if (e is ParserConfigurationException) { if (Trace.error) SupportClass.WriteStackTrace(e, Console.Error); return false; } else if (e is System.IO.IOException) { throw (System.IO.IOException) e; } else { SupportClass.WriteStackTrace(e, Console.Error); return true; } } finally { in_Renamed.Close(); } }
/** * Reads in the binary file specified. * * <p>If there are any problems reading in the file, it gets classified as unidentified, * with an explanatory warning message. */ private void readFile() { //If file is not readable or is empty, then it gets classified //as unidentified (with an explanatory warning) if( !file.Exists ) { this.SetErrorIdentification(); this.SetIdentificationWarning("File does not exist"); return; } //TODO: figure out how to port this /* if( !file.canRead() ) { this.SetErrorIdentification(); this.SetIdentificationWarning("File cannot be read"); return; } */ if (System.IO.Directory.Exists(file.FullName)) { this.SetErrorIdentification(); this.SetIdentificationWarning("This is a directory, not a file"); return; } //FileInputStream binStream; System.IO.FileStream binStream; try { binStream = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open); //FileInputStream(file); } catch (System.IO.FileNotFoundException) { this.SetErrorIdentification(); this.SetIdentificationWarning("File disappeared or cannot be read"); return; } try { int numBytes = 100; //binStream.available(); if (numBytes > 0) { //BufferedInputStream buffStream = new BufferedInputStream(binStream); System.IO.BufferedStream buffStream = new System.IO.BufferedStream(binStream); fileBytes = new byte[numBytes]; int len = buffStream.Read(fileBytes, 0, numBytes); if(len != numBytes) { //This means that all bytes were not successfully read this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: "+ len.ToString() + " bytes read from file when " + numBytes.ToString() + " were expected"); } else if(len != -1) { //This means that the end of the file was not reached this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: Unable to read to the end"); } else { myNumBytes = (long) numBytes; } buffStream.Close(); } else { //If file is empty , status is error this.SetErrorIdentification(); myNumBytes = 0L; this.SetIdentificationWarning("Zero-length file"); } binStream.Close(); isRandomAccess = false; } catch(System.IO.IOException e) { this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: " + e.ToString()); } catch(System.OutOfMemoryException) { try { myRandomAccessFile = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open); //RandomAccessFile(file,"r"); isRandomAccess = true; //record the file size myNumBytes = myRandomAccessFile.Length; //try reading in a buffer myRandomAccessFile.Seek(0, System.IO.SeekOrigin.Begin); //(0L); bool tryAgain = true; while(tryAgain) { try { fileBytes = new byte[(int)randomFileBufferSize]; myRandomAccessFile.Read(fileBytes, 0, randomFileBufferSize); // .read(fileBytes); tryAgain = false; } catch(OutOfMemoryException e4) { randomFileBufferSize = randomFileBufferSize/RAF_BUFFER_REDUCTION_FACTOR; if(randomFileBufferSize< MIN_RAF_BUFFER_SIZE) { throw e4; } } } myRAFoffset = 0L; } catch (System.IO.FileNotFoundException) { this.SetErrorIdentification(); this.SetIdentificationWarning("File disappeared or cannot be read"); } catch(Exception e2) { try { myRandomAccessFile.Close(); } catch(System.IO.IOException) { } this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: " + e2.ToString()); } } }
/** * Reads in the binary file specified. * * <p>If there are any problems reading in the file, it gets classified as unidentified, * with an explanatory warning message. */ private void readFile() { //If file is not readable or is empty, then it gets classified //as unidentified (with an explanatory warning) if (!file.Exists) { this.SetErrorIdentification(); this.SetIdentificationWarning("File does not exist"); return; } //TODO: figure out how to port this /* * if( !file.canRead() ) * { * this.SetErrorIdentification(); * this.SetIdentificationWarning("File cannot be read"); * return; * } */ if (System.IO.Directory.Exists(file.FullName)) { this.SetErrorIdentification(); this.SetIdentificationWarning("This is a directory, not a file"); return; } //FileInputStream binStream; System.IO.FileStream binStream; try { binStream = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open); //FileInputStream(file); } catch (System.IO.FileNotFoundException) { this.SetErrorIdentification(); this.SetIdentificationWarning("File disappeared or cannot be read"); return; } try { int numBytes = 100; //binStream.available(); if (numBytes > 0) { //BufferedInputStream buffStream = new BufferedInputStream(binStream); System.IO.BufferedStream buffStream = new System.IO.BufferedStream(binStream); fileBytes = new byte[numBytes]; int len = buffStream.Read(fileBytes, 0, numBytes); if (len != numBytes) { //This means that all bytes were not successfully read this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: " + len.ToString() + " bytes read from file when " + numBytes.ToString() + " were expected"); } else if (len != -1) { //This means that the end of the file was not reached this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: Unable to read to the end"); } else { myNumBytes = (long)numBytes; } buffStream.Close(); } else { //If file is empty , status is error this.SetErrorIdentification(); myNumBytes = 0L; this.SetIdentificationWarning("Zero-length file"); } binStream.Close(); isRandomAccess = false; } catch (System.IO.IOException e) { this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: " + e.ToString()); } catch (System.OutOfMemoryException) { try { myRandomAccessFile = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open); //RandomAccessFile(file,"r"); isRandomAccess = true; //record the file size myNumBytes = myRandomAccessFile.Length; //try reading in a buffer myRandomAccessFile.Seek(0, System.IO.SeekOrigin.Begin); //(0L); bool tryAgain = true; while (tryAgain) { try { fileBytes = new byte[(int)randomFileBufferSize]; myRandomAccessFile.Read(fileBytes, 0, randomFileBufferSize); // .read(fileBytes); tryAgain = false; } catch (OutOfMemoryException e4) { randomFileBufferSize = randomFileBufferSize / RAF_BUFFER_REDUCTION_FACTOR; if (randomFileBufferSize < MIN_RAF_BUFFER_SIZE) { throw e4; } } } myRAFoffset = 0L; } catch (System.IO.FileNotFoundException) { this.SetErrorIdentification(); this.SetIdentificationWarning("File disappeared or cannot be read"); } catch (Exception e2) { try { myRandomAccessFile.Close(); } catch (System.IO.IOException) { } this.SetErrorIdentification(); this.SetIdentificationWarning("Error reading file: " + e2.ToString()); } } }
private static bool isZip(System.Uri url) { System.IO.Stream in_Renamed = new System.IO.BufferedStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream()); try { return isZip(in_Renamed); } finally { in_Renamed.Close(); } }
private static void dumpZip(System.IO.StreamWriter out_Renamed, System.Uri url, System.String outfile) { System.IO.Stream in_Renamed = new System.IO.BufferedStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream()); try { //UPGRADE_ISSUE: Class 'java.util.zip.ZipInputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'" //UPGRADE_ISSUE: Constructor 'java.util.zip.ZipInputStream.ZipInputStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'" ZipInputStream zipIn = new ZipInputStream(in_Renamed); //UPGRADE_ISSUE: Class 'java.util.zip.ZipEntry' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipEntry'" //UPGRADE_ISSUE: Method 'java.util.zip.ZipInputStream.getNextEntry' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'" ZipEntry zipEntry = zipIn.getNextEntry(); while ((zipEntry != null)) { //UPGRADE_TODO: Class 'java.net.URL' was converted to a 'System.Uri' which does not throw an exception if a URL specifies an unknown protocol. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1132'" //UPGRADE_ISSUE: Method 'java.util.zip.ZipEntry.getName' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipEntry'" System.Uri fileUrl = new System.Uri("jar:" + url.ToString() + "!/" + zipEntry.getName()); if (isSwf(fileUrl)) dumpSwf(out_Renamed, fileUrl, outfile); //UPGRADE_ISSUE: Method 'java.util.zip.ZipInputStream.getNextEntry' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javautilzipZipInputStream'" zipEntry = zipIn.getNextEntry(); } } finally { in_Renamed.Close(); } }
public static void Main(System.String[] args) { if (args.Length == 0) { System.Console.Error.WriteLine("Usage: java tools.SwfxPrinter [-encode] [-asm] [-abc] [-noactions] [-showdebugsource] [-showoffset] [-noglyphs] [-external] [-save file.swf] [-nofunctions] [-out file.swfx] file1.swf ..."); System.Environment.Exit(1); } int index = 0; System.IO.StreamWriter out_Renamed = null; System.String outfile = null; while ((index < args.Length) && (args[index].StartsWith("-"))) { if (args[index].Equals("-encode")) { encodeOption = true; ++index; } else if (args[index].Equals("-save")) { ++index; saveOption = true; outfile = args[index++]; } else if (args[index].Equals("-decompile")) { decompileOption = true; ++index; } else if (args[index].Equals("-nofunctions")) { defuncOption = false; ++index; } else if (args[index].Equals("-asm")) { decompileOption = false; ++index; } else if (args[index].Equals("-abc")) { abcOption = true; ++index; } else if (args[index].Equals("-noactions")) { showActionsOption = false; ++index; } else if (args[index].Equals("-showoffset")) { showOffsetOption = true; ++index; } else if (args[index].Equals("-showdebugsource")) { showDebugSourceOption = true; ++index; } else if (args[index].Equals("-noglyphs")) { glyphsOption = false; ++index; } else if (args[index].Equals("-out")) { if (index + 1 == args.Length) { System.Console.Error.WriteLine("-out requires a filename or - for stdout"); System.Environment.Exit(1); } if (!args[index + 1].Equals("-")) { outfile = args[index + 1]; //UPGRADE_TODO: Constructor 'java.io.FileOutputStream.FileOutputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileOutputStreamFileOutputStream_javalangString_boolean'" out_Renamed = new System.IO.StreamWriter(SupportClass.GetFileStream(outfile, false), System.Text.Encoding.Default); } index += 2; } else if (args[index].Equals("-external")) { externalOption = true; ++index; } else if (args[index].ToUpper().Equals("-tabbedGlyphs".ToUpper())) { tabbedGlyphsOption = true; ++index; } else { System.Console.Error.WriteLine("unknown argument " + args[index]); ++index; } } if (out_Renamed == null) { System.IO.StreamWriter temp_writer; temp_writer = new System.IO.StreamWriter(System.Console.OpenStandardOutput(), System.Text.Encoding.Default); temp_writer.AutoFlush = true; out_Renamed = temp_writer; } System.IO.FileInfo f = new System.IO.FileInfo(args[index]); System.Uri[] urls; bool tmpBool; if (System.IO.File.Exists(f.FullName)) tmpBool = true; else tmpBool = System.IO.Directory.Exists(f.FullName); if (!tmpBool) { //UPGRADE_TODO: Class 'java.net.URL' was converted to a 'System.Uri' which does not throw an exception if a URL specifies an unknown protocol. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1132'" urls = new System.Uri[]{new System.Uri(args[index])}; } else { if (System.IO.Directory.Exists(f.FullName)) { System.IO.FileInfo[] list = FileUtils.listFiles(f); urls = new System.Uri[list.Length]; for (int i = 0; i < list.Length; i++) { urls[i] = FileUtils.toURL(list[i]); } } else { urls = new System.Uri[]{FileUtils.toURL(f)}; } } for (int i = 0; i < urls.Length; i++) { try { System.Uri url = urls[i]; if (saveOption) { System.IO.Stream in_Renamed = new System.IO.BufferedStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream()); try { //UPGRADE_TODO: Constructor 'java.io.FileOutputStream.FileOutputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileOutputStreamFileOutputStream_javalangString'" System.IO.Stream fileOut = new System.IO.BufferedStream(new System.IO.FileStream(outfile, System.IO.FileMode.Create)); try { int c; while ((c = in_Renamed.ReadByte()) != - 1) { fileOut.WriteByte((System.Byte) c); } } finally { fileOut.Close(); } } finally { in_Renamed.Close(); } } if (isSwf(url)) { dumpSwf(out_Renamed, url, outfile); } else if (isZip(url) && !url.ToString().EndsWith(".abj")) { dumpZip(out_Renamed, url, outfile); } else { //UPGRADE_TODO: Method 'java.io.PrintWriter.println' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioPrintWriterprintln_javalangString'" out_Renamed.WriteLine("<!-- Parsing actions from " + url + " -->"); // we have no way of knowing the swf version, so assume latest System.Net.HttpWebRequest connection = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(url); ActionDecoder actionDecoder = new ActionDecoder(new SwfDecoder(connection.GetResponse().GetResponseStream(), 7)); actionDecoder.KeepOffsets = true; int ContentLength; try { ContentLength = System.Int32.Parse(connection.GetResponse().Headers.Get("Content-Length")); } catch (System.IO.IOException e) { ContentLength = -1; } ActionList actions = actionDecoder.decode(ContentLength); SwfxPrinter printer = new SwfxPrinter(out_Renamed); printer.decompile = decompileOption; printer.defunc = defuncOption; printer.printActions(actions); } out_Renamed.Flush(); } catch (System.ApplicationException e) { if (Trace.error) SupportClass.WriteStackTrace(e, Console.Error); System.Console.Error.WriteLine(""); System.Console.Error.WriteLine("An unrecoverable error occurred. The given file " + urls[i] + " may not be"); System.Console.Error.WriteLine("a valid swf."); } catch (System.IO.FileNotFoundException e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" System.Console.Error.WriteLine("Error: " + e.Message); System.Environment.Exit(1); } } }