/// <summary>this method writes the GeneratedClass object to disk</summary> /// <param name="gc">the object to be written to disk /// </param> /// <param name="packageName">representing the packageName /// </param> /// <param name="fileName">representing the file name /// </param> /// <exception cref="IOException">if unable to create file /// </exception> public virtual void storeFile(GeneratedClass gc, System.String packageName, System.String fileName) { //format package name packageName = packageName.Replace('.', '/'); // set the file path fileName = Regex.Replace(fileName, " ", "") + ".java"; System.String filePath = basePath + "/" + packageName + "/" + fileName; System.IO.FileInfo f = new System.IO.FileInfo(filePath); System.Text.StringBuilder dir = new System.Text.StringBuilder(); //check if file exist // TODO: Reactivate this once everything works! //if(f.exists()) // throw new IOException("File already exists"); //create subfolders int i = 0; while (i < filePath.Length) { if (filePath[i] != '/') { dir.Append(filePath[i]); } else { dir.Append(filePath[i]); System.IO.FileInfo d = new System.IO.FileInfo(dir.ToString()); System.IO.Directory.CreateDirectory(d.FullName); } ++i; } System.IO.FileStream fstream = new System.IO.FileStream(f.FullName, System.IO.FileMode.Create); /* open file stream */ System.IO.BinaryWriter ostream = new System.IO.BinaryWriter(fstream); /* open object stream */ ostream.Write(gc.ToString()); /* clean-up */ ostream.Flush(); fstream.Close(); }
/// <summary>This method is used to generate a file containng the Generated Class</summary> /// <param name="gc">the Generated Class /// </param> /// <param name="packageName">the name of the package /// </param> /// <param name="filename">the name to save the generated class under /// </param> public virtual void generateFile(GeneratedClass gc, System.String packageName, System.String filename) { //fg.storeFile(gc, filename, packageName); try { fg.storeFile(gc, packageName, filename); } catch (System.IO.IOException e) { System.Console.Error.WriteLine(e.Message); } }