Breaking Down Classes Into Files

I'd like to know what's considered best practice when dividing multiple classes into seperate files. I know you can have only one public class per file, and I've heard some people say it's best to have one class per file, period. But the one-class-per-file rule seems overly strict.
To give a specific example, I have a class which manages event handlers and event generators. The class receives events and delegates them to one of its registered handlers. The handlers can, in turn, spawn new events by calling the event generators, which have package access.
Currently, I have the handlers, the generators, and the public class which manages them all in one file, which I know is not good, especially since some of the handlers and some of the generators are fairly large classes in their own right. However, it would be silly (I think) to put every handler and every generator in its file, because some of them are almost trivially small, and none of them have public access. But what is the best way to break them down: Should I put the handlers all in one file, and the generators all in one file, giving me three files total? Or are there other principles that should guide me?
Thanks for any thoughts,
John

That's a good point. Although, as you said, it
doesn't really apply in my case. That is, if I put
all the handlers in a file called EventHandlers.java,
that should be pretty clear for me. And, in fact, it
would probably be easier to work with the classes if
they are all in one file.But what do you think about when I say reuse? Don't you think that one class per file will make it easier to reuse the classes? As it is now you have to take them all. Since you have things that are in common for them I would say that you must have interfaces, and abstract classes. Couldn't they be reused in another project? So there are benefits even in small projects. It's also better to have many files if there are several developers and your version manager doesn't allow multiple checkouts of the same file.
>
Also, you mentioned sub-packages. I'm assuming
classes in sub-packages do not have access to their
parent's package-access members. What I really would
like is to prevent any classes except the event
handlers from accessing my EventManager's generator
members. Could you solve that problem in another way? Why do they need access to the EventManager?
Are you saying I should put all the other
classes in a sub-package? I say that you should put related classes in sub-packages. Look at the package structure of the java core (can be seen in the javadoc)
/Kaj

Similar Messages

  • How to break report output into files

    Hi,
    I need to submit my report output into different files based on the Sales person name.
    When I submit my request from SRS window it asks the sales person name 'FROM' and 'To'parameters, if I choose the different sales person names then report output has to divide into files for each sales person. How can I do this? Do I nedd to add any code
    in my report.
    Could you help me in this?
    Thanks in advance

    This maybe helpful:
    Report Distribution

  • Breaking down a VOB file for clip edting in final cut pro

    I have a client that shot some video of their farm this past week and they want us to edit portions of the video. Of course this is one huge .VOB file. I have the the entire VIDEO_TS file folder but I have yet to find a way to capture clips from this file?
    Is there a way to capture any of this without having to make multiple copies of the file? It is a lot large than I would like 800MB.

    I figured it out Thanks for the help/___sbsstatic___/migration-images/migration-img-not-avail.png/___sbsstatic_ __/migration-images/migration-img-not-avail.png/___sbsstatic___/migration-images /migration-img-not-avail.png It was greatly appreciated.

  • How to convert .class into .jar file

    Hi,
    How to convert .class into .jar file

    jsf_VWP5.5.1 wrote:
    Hi,
    How to convert .class into .jar fileFrom a command prompt, cd to the location of your .class file(s).
    If you want to create a simple jar, use: jar -cf Whatever.jar Whatever.class
    If you want to compile all .class files in a directory into a jar, use *.class instead.
    Now, I'm going to assume you want to create an executable jar... here's how to do that:
    1) Create a blank text file; for this example, lets call it main.txt.
    2) In the first line of main.txt, type: Main-class: Whatever ('Whatever' should be the name of the class in your program where the main() method is located)
    3) Press enter to go to the next line (someone please correct me if I'm wrong, but if you don't insert the line break/CR after the Main-class: statement, this will not work... in my experience, this is true)
    4) Make sure you save this file in the same directory as your .class file(s).
    5) Type: jar -cmf Whatever.jar main.txt Whatever.class
    ...and that's about it. For more information on the usage of the jar command and to understand the switches (such as -cmf), try jar --help.
    Hope that helps.

  • How do I break my codes into classes??

    How do i break each tab into a class and call them inside a main program ??
    Please show me how thanks.
    import javax.swing.JTabbedPane;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.BorderFactory;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import java.sql.*;
    import java.io.*;
    public class DatabaseApp extends JPanel {
         // declare the width and height of UI
         public static int WIDTH = 800;
         public static int HEIGHT = 600;
         // create textfield objects for user to enter the input
         TextField employeeID = new TextField(15);
         TextField name = new TextField(40);
         TextField address = new TextField(40);
         TextField suburb = new TextField(20);
         TextField state = new TextField(5);
         TextField pCode = new TextField(5);
         TextField dob = new TextField(15);
         TextField homePh = new TextField(15);
         TextField workPh = new TextField(15);
         TextField mobile = new TextField("0",15);
         TextField eMail = new TextField(30);
         TextField dbase = new TextField("employee",20);
         TextField report = new TextField(15);
         TextField query= new TextField(50);
         TextArea displayArea = new TextArea(16,80);
         TextArea helpArea = new TextArea(20,80);
         public static void main (String[] args) {
              JFrame frame = new JFrame ("S-League Management System");
              frame.addWindowListener(new WindowAdapter(){
                        public void windowClosing (WindowEvent e) {
                             System.exit(0);
              frame.getContentPane().add(new DatabaseApp(), BorderLayout.CENTER);
              frame.setSize(800,600);
              frame.setResizable(false);
              frame.setVisible(true);
              //centralise the screen
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              Dimension frameSize = frame.getSize();
              frame.setLocation((screenSize.width - frameSize.width) / 2,
                   (screenSize.height - frameSize.height) / 2);
         /** add buttons to the database form
         public JButton(String text,Icon icon)
         Creates a button with initial text and an icon.
         Parameters:
         text - the text of the button.
         icon - the Icon image to display on the button
         JButton newButton = new JButton (" New ", new ImageIcon(DatabaseApp.class.getResource("img/New.gif")));
         JButton addButton = new JButton (" Add ", new ImageIcon (DatabaseApp.class.getResource("img/Add.gif")));
         JButton findButton = new JButton (" Retrieve ", new ImageIcon (DatabaseApp.class.getResource("img/Find.gif")));
         JButton updateButton = new JButton (" Update ", new ImageIcon (DatabaseApp.class.getResource("img/Refresh.gif")));
         JButton deleteButton = new JButton (" Delete ", new ImageIcon (DatabaseApp.class.getResource("img/Delete.gif")));
         JButton submitButton = new JButton (" Submit Query ", new ImageIcon (DatabaseApp.class.getResource("img/Export.gif")));
         JButton reportButton = new JButton (" Report File ", new ImageIcon (DatabaseApp.class.getResource("img/AlignLeft.gif")));
         /** create tabbed pane for form
         * public void addTab(String title,Icon icon,Component component,String tip)
         * Parameters:
         * title - the title to be displayed in this tab
         * icon - the icon to be displayed in this tab
         * component - The component to be displayed when this tab is clicked.
         * tip - the tooltip to be displayed for this tab
         public DatabaseApp() {
              // create new tabbedPane object
              JTabbedPane tabbedPane = new JTabbedPane(){
                   ImageIcon imageIcon = new ImageIcon("img/logo.jpg");
                   Image image = imageIcon.getImage();
                   public void paintComponent (Graphics g) {
                        g.setColor(new Color(220,220,220));
                        g.fillRect(0,0,643,74);
                        g.drawImage(image, 0, 4, this);
                        super.paintComponent(g);
              tabbedPane.addTab(" Team Management ",null, buildQueryPanel(), "Team Management");
              tabbedPane.addTab(" Player Registration ",null, buildGeneralPanel(), "Player Registration");
              tabbedPane.addTab(" Author ",null, buildAuthorPanel(), "Author");
              // assign layout manager
              //setLayout(new GridLayout(1,1));
              tabbedPane.setSelectedIndex(1);
              tabbedPane.setBorder(BorderFactory.createEmptyBorder(78,0,0,0));
              add(tabbedPane);
         protected JPanel buildQueryPanel() {
              JPanel mainPane = new JPanel();
              // divided into three panes. these panes will be added to mainPanel
              JPanel westPane = new JPanel();
              JPanel centrePane = new JPanel();
              JPanel southPane = new JPanel();
              // assign the layout managers
              mainPane.setLayout(new BorderLayout());
              westPane.setLayout(new GridLayout(4,1));
              centrePane.setLayout(new GridLayout(4,1));
              // create array of Panels for label textfield and buttons and make them left align
              Panel labelPane[] = new Panel[4];
              Panel buttontxtPane[] = new Panel[4];
              Panel textPane[] = new Panel[1];
              for (int i=0; i < labelPane.length; ++i) {
                   labelPane[i] = new Panel();
                   labelPane.setLayout(new FlowLayout(FlowLayout.LEFT));
              for (int i=0; i < buttontxtPane.length; ++i) {
                   buttontxtPane[i] = new Panel();
                   buttontxtPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
              for (int i=0; i < textPane.length; ++i) {
                   textPane[i] = new Panel();
                   textPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
              // add different label to the labelPane
              labelPane[0].add(new JLabel("Database:"));
              labelPane[1].add(new JLabel("Query:"));
              labelPane[2].add(new JLabel("Report File:"));
              labelPane[3].add(new Label(""));
              // textfields
              buttontxtPane[0].add(dbase);
              buttontxtPane[1].add(query);
              buttontxtPane[2].add(report);
              // buttons
              buttontxtPane[3].add(submitButton);
              submitButton.setMnemonic('s');
              buttontxtPane[3].add(reportButton);
              reportButton.setMnemonic('r');
              // text area to view the result
              textPane[0].add(displayArea);
              // add action listener to buttons
              submitButton.addActionListener(new ButtonHandler());
              reportButton.addActionListener(new ButtonHandler());
              for(int i=0; i < labelPane.length; ++i)
                   westPane.add(labelPane[i]);
              for(int i=0; i < buttontxtPane.length; ++i)
                   centrePane.add(buttontxtPane[i]);
              for(int i=0; i < textPane.length; ++i)
                   southPane.add(textPane[i]);
              mainPane.add(westPane, BorderLayout.WEST);
              mainPane.add(centrePane, BorderLayout.CENTER);
              mainPane.add(southPane,BorderLayout.SOUTH);
              return mainPane;
         /**Create a JPanel for General tab, divide it into three JPanels for label, displaytext
         * and buttons.Assign a Flowlayout manager to each panel. Add label, textfield
         * and buttons to respective panel. following constructors will be used
         * for Jlabel
         * public JLabel(String text)
         * Creates a JLabel instance with the specified text. The label is aligned against the leading edge of its display area, and centered vertically.
         * Parameters:
         * text - The text to be displayed by the label.
         protected Component buildGeneralPanel() {
              // main panel
              JPanel mainPanel = new JPanel();
              // divided into three panes. these panes will be added to mainPanel
              JPanel westPane = new JPanel();
              JPanel centrePane = new JPanel();
              JPanel southPane = new JPanel();
              // assign the layout managers
              mainPanel.setLayout(new BorderLayout());
              westPane.setLayout(new GridLayout(12,1));
              centrePane.setLayout(new GridLayout(12,1));
              // create array of Panels for label textfield and buttons and make them left align
              Panel labelPane[] = new Panel[12];
              Panel textPane[] = new Panel[12];
              Panel buttonPane[] = new Panel[2];
              for (int i=0; i < labelPane.length; ++i) {
                   labelPane[i] = new Panel();
                   labelPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
              for (int i=0; i < textPane.length; ++i) {
                   textPane[i] = new Panel();
                   textPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
              for (int i=0; i < buttonPane.length; ++i) {
                   buttonPane[i] = new Panel();
                   buttonPane[i].setLayout(new FlowLayout(FlowLayout.LEFT));
              // add different label to the labelPane
              labelPane[0].add(new JLabel("Employee No"));
              labelPane[1].add(new JLabel("Name"));
              labelPane[2].add(new JLabel("Address"));
              labelPane[3].add(new JLabel("Suburb"));
              labelPane[4].add(new JLabel("State"));
              labelPane[5].add(new JLabel("PostCode"));
              labelPane[6].add(new JLabel("Date of Birth"));
              labelPane[7].add(new JLabel("Home Phone"));
              labelPane[8].add(new JLabel("Work Phone"));
              labelPane[9].add(new JLabel("Mobile"));
              labelPane[10].add(new JLabel("E-mail"));
              // add textfield component to textPane
              textPane[0].add(employeeID);
              textPane[1].add(name);
              textPane[2].add(address);
              textPane[3].add(suburb);
              textPane[4].add(state);
              textPane[5].add(pCode);
              textPane[6].add(dob);
              textPane[7].add(homePh);
              textPane[8].add(workPh);
              textPane[9].add(mobile);
              textPane[10].add(eMail);
              // add button to buttonPane and assign keyboard key for shortcut e.g Alt + n
              buttonPane[0].add(newButton);
              newButton.setMnemonic('n');
              buttonPane[0].add(addButton);
              addButton.setMnemonic('a');
              buttonPane[0].add(findButton);
              findButton.setMnemonic('r');
              buttonPane[0].add(updateButton);
              updateButton.setMnemonic('u');
              buttonPane[0].add(deleteButton);
              deleteButton.setMnemonic('d');
              // add actionlistener to the buttons
              newButton.addActionListener(new ButtonHandler());
              addButton.addActionListener(new ButtonHandler());
              findButton.addActionListener(new ButtonHandler());
              updateButton.addActionListener(new ButtonHandler());
              deleteButton.addActionListener(new ButtonHandler());
              for (int i = 0; i < labelPane.length; ++i)
                   westPane.add(labelPane[i]);
              for (int i = 0; i < textPane.length; ++i)
                   centrePane.add(textPane[i]);
              for (int i = 0; i < buttonPane.length; ++i)
                   southPane.add(buttonPane[i]);
              mainPanel.add(westPane,BorderLayout.WEST);
              mainPanel.add(centrePane,BorderLayout.CENTER);
              mainPanel.add(southPane,BorderLayout.SOUTH);
              return mainPanel;
         protected JPanel buildAuthorPanel(){
              JPanel authorPanel = new JPanel();
              JPanel authorPane = new JPanel();
              authorPanel.setLayout(new BorderLayout());
              authorPane.setLayout(new GridLayout(9,1));
              Panel pane[] = new Panel[9];
              for (int i=0; i < pane.length; i++) {
                   pane[i] = new Panel();
                   pane[i].setLayout(new FlowLayout(FlowLayout.CENTER));
              pane[0].add(new JLabel(""));
              pane[1].add(new JLabel(""));
              pane[2].add(new JLabel(""));
              pane[3].add(new JLabel(""));
              pane[4].add(new JLabel("Name:Jasper Lim Jiqiang"));
              pane[5].add(new JLabel("Admin:992365G"));
              pane[6].add(new JLabel(""));
              pane[7].add(new JLabel(""));
              pane[8].add(new JLabel(""));
              for (int i=0; i < pane.length; i++)
                   authorPane.add(pane[i]);
              authorPanel.add(authorPane, BorderLayout.CENTER);
              return authorPanel;

    Maybe something like this:
    <code>
    JTabbedPane tabbedPane = new JTabbedPane();
              JPanel introPanel = new JPanel();
              introPanel.add(createIntroPanel());
              ImageIcon img = new ImageIcon(getResourceString("tabIconFile"));
              tabbedPane.addTab(getResourceString("introTab"), img, introPanel);
    </code>
    plus
    <code>
    protected JPanel createIntroPanel()
              JPanel pane = new IntroPanel();
              return pane;
    </code>
    Klint

  • How can I split a class into 2 files?

    I converted a C++ program to Java recently and it works fine, but I ran into a problem.
    One file is very large and I need to add more functionality. Unlike with C++ where you can just put new functions in another file, I don't see a way to do it in Java.
    I made another file, and therefore another class, but the compiler complains that it can't call a static function from non-static context. (I did not declare it static so I guess it's assuming it) But I understand why. So I made the new class "extend" the old one so "this" would exist but that doesn't work -- Is it because the new class is a subclass of the original class?
    There must be a way to do this. But I don't see what is likely obvious. HELP! And thanks.

    JavaIsBetterThanCPP wrote:
    There must be a way to do this. But I don't see what is likely obvious. HELP! And thanks.Unfortunately Java has no concept of "partial classes" like C# has. Generally, however, a class that is large enough to split up into separate files is either one class that should be modularized further into separate classes, or it already is modularized and all that code is the result of many inner classes. What some people do is promote those inner classes to top-level members in their own file, and mark them as package-private. Using a package you can basically have two classes that know everything about each other and have full access to each other.
    But personally, and until I see justification otherwise, semantics in Java being unbreakingly tied to a certain file structure and naming is the most bonehead and, frankly, non-Java thing about Java.
    There's probably a pre-processor out there that will let you split a class into multiple files and will combine them into a single source file just-in-time to pass to the compiler.

  • Class into an XML file into a DataSet vs. Reflection into a DataTable

    In order to serialize a class (SystemSetup) and load an XML file into a datatable and then a dataset I must:
    1. Create an .XSD file using the XSD SDK tool.
    2. DataTable.LoadSchemaFile
    3. DataTable.LoadXml
    4. Then add the datatable to a dataset.
    Is this correct?
    Another method using Reflection. 
    Reflect the SystemSetup class into a datatable.
    Push the datatable->dataset to the crystal report.
    Will this work?
    Which one is preferable?  Thx.,
    Ajay

    OK, i figured this much out:
    Dim ds As New DataSet
            Dim myXmlReader As New System.Xml.XmlTextReader("C:\SystemSetup.xml")
            ds.ReadXml(myXmlReader, XmlReadMode.InferTypedSchema)
            mydatatable = ds.Tables(0)

  • How do I break up a pdf file into smaller files?

    I have a huge pdf file that I am trying to send as an attachment but it is too large to send.  I need to break it up into about 10 different files.  Any help would be appreciated.

    Hi sbills04,
    To split a PDF (or extract pages), you need to use Acrobat. Please see https://acrobatusers.com/tutorials/how-to-break-a-pdf-into-parts
    Please let us know if you have additional questions.
    Best,
    Sara

  • Does loading too many classes into jvm slow down performance?

    hi all,
    does loading too many classes into jvm will slow down performance. Our application is CPU bound, if we use any framework we need to load all the classes related to that framework in JVM. Does this have any effect on the performance of the JVM.
    thanks and regards,
    akmal

    does loading many classes into jvm slow down performance.It will increase the time it takes for the JVM to load your application.
    Our application is CPU boundThe time it takes the JVM to load your application is not likely to be an issue for you then.

  • Loading values into drop down through properties file.

    Hi all,
    Can any one please let me know how to read a drop down through properties file I have two drop downs. I need to read the drop down values through the properties file .
    I would appreciate if you can provide me with the sample code to do this(i mean similar kind of operation)
    Say for example
    if i have in the properties file
    months.properties
    Month = "january,february,march.....december"
    january = "monday,tuesday, wednesday"
    for the first drop down i need to load the months i.e., january, february, march etc.
    After selecting the first drop down say january, then it should show me monday,tuesday and wednesday in the second drop down.
    I know it's a begineers question. any help would be appreciated.
    Thanks in advance for your help
    regards,
    sam

    Actually i want to use Jstl tag for this
    <select name="secQst1">
    <c:forEach var="flaglistdetail" items="${flaglist}">
    <option value="<c:out value="${flaglistdetail.seqId}"/>"><c:out value="${flaglistdetail.seqDesc}"/></option>
    </c:forEach>
    </select>
    The above operation is for getting the drop down values for the database. I want to hard code the values in the properties file and read it in the action and want to get it through the select tag.
    private Properties _appConfig;
         private static final String APP_CONFIG_NAME = "AppConfigProperties.properties";
    if (_appConfig == null) {
    _appConfig = new Properties();
    try {
    appConfig.load(FileUtil.getFileAsStream(APPCONFIG_NAME));
    } catch (Exception e) {
    throw new RuntimeException("can not find "
    + APP_CONFIG_NAME, e);
    I was trying to do the above thing. but for some reason i couldn't get it.
    if you have any sample code which does the same thing like this would be helpful

  • Breaking down Spry Data Repeat

    Hi,
    I'm trying to create a spry data set  in a table from a XML data file. I have done that in below are the  codings I obtained from Spry tool.
    <div  spry:region="KomtarETA">
      <table>
        <tr  class="TableHeader">
          <td width="100">Route</td>
           <td width="1266">Current</td>
          <td  width="1366">Destination</td>
          <td  width="1266">Next</td>
          <td  width="100">Lane</td>
        </tr>
        <tr  class="TableContent" spry:repeat="KomtarETA">
           <td>{route}</td>
          <td>{desitnation</td>
           <td>{current}</td>
          <td>{next}</td>
           <td>>{lane}</td>
    I have some individual  codings need to be done on each individual  data field. I need to  seperate all the spry data into each individual  column.
    My question  is how I can control these data individually when it's in the table ? Is  there any codings changes need to be done ?
    Please advise.
    Thanks.

    Hi,
    Actually what I mean by breaking down the data and not by means of filtering.
    I still want to display every single data but I wan it to be individualised.
    Here's the link to the test site.
    http://www.pcsb.my/test/KomtarETA.html
    What I need is that some column will be static and some will be dynamic. The actual external XML data will be dynamic as there will be a live server feeding and overwritting it.
    If you look at the Spry table portion coding inside the HTML file, it's actually a Spry repeat and I don't have much control over each individual data I want to manipulate the codings.
    Please take a look at it.
    Thanks.

  • Is there a script (or plugin) that will take a photo and break it up into parts?

    Is there a script or plug-in out there that will take a picture and break it up into various parts (squares for example.)  The idea would be that you could automate and rapidly create a photo collage of a single image.  (See examples of what I mean in attached pics.)
    Thanks!
    This image has been resized to fit in the page. Click to enlarge.
    You get the idea.

    OK, I'm going to edit this post now that I'm at a computer with an actual step by step.
    Create a new comp the size of you our final delivered project.
    Add a photo to the timeline
    Note the size of the photo and the scale to position the photo at it's final resting place
    Calculate twice the height and width of the photo and create a new solid that is this size
    Place the solid above the photo
    Create a mask in the solid at the exact center that is the size shape you want for your photo frame
    Either invert the mask or set the mask property to Subtract to reveal a small portion of the photo
    Set the solid as a alpha inverted track matte for the photo (you should now see only a portion of the photo
    Add a rectangular shape layer with only a stroke to act as the photo frame over the mask. You may have to use two shapes or create a mask on a shape if you want to simulate polaroids
    Make the shape layer the parent of the solid you are using as a track matte so the matte will stay lined up with the frame
    Here comes the fun, select all layers and duplicate them using Ctrl/Cmnd + D
    Immediately hold down Shift + Ctrl/Cmnd + } to move all duplicates to the top
    Select the top shape layer and move the shape layer frame into a new position
    Pre-compose the top 3 layers
    Press the y key to select the Pan Benind or Anchor Point tool and move the pre-comp's anchor point to the center of the top frame
    Repeat step 11 through 15 until you have arranged your montage (it might be a good idea to have a template set up as a guide layer so you know where to put the frames
    Select all pre-comps and press Alt/Option + P to set a position keyframe for each pre-comp
    With all of the keyframe selected move them down the timeline about 3 seconds
    Now, with the CTI at the first frame drag each pre-comp into a starting position for that frame
    Preview and adjust the timing, then turn on motion blur
    Your images will now assemble themselves into the final montage.
    There is no script that I know of that will do all of this automatically, but it would not be too hard to write a script that would do the pre-composing if you have a ton of these to do. I'm guessing that with a little practice you could have a new picture frame created and moved into position in less than a minute. It takes me about 30 seconds. That means a 20 frame sequence should take you about a half hour. It might not be worth writing a script unless you have a ton of these to do. Select the bottom three layers and duplicate (Ctrl/Cmnt + D), group them at the top (Shift + Ctrl/Cmnd + } ), move the top frame layer into position, then Shift + Ctrl/Cmnd + C to pre-compose, then move the anchor point of the pre-comp, then do it again.... When you're done set a few keyframes.
    As I said, you could write a script, but you'd need a different script to move each frame into position and the script would only work for one layout. If you made a template to put on the bottom so you knew where do place the frames and which order you wanted them you could do this by hand very quickly. The sample project that I'm including which was just quickly thrown together took me less than 10 minutes. Replace my photo with one of yours and you'll get the idea.
    Dropbox - photoMontage1_CS6.aep (Note: Dropbox will probably add a .txt extension to the .aep file. Just delete it and you should be able to open the project.

  • Store pdf from ArchiveLink (binary) down to Netweaver file system

    Hello!
    I have a problem: I need to extract a pdf-file which is stored in table TOA01 in binary format. The pdf should be generated and stored into a pdf-file in the file system of the Netweaver application server.
    The main problem: Whenever I extract the data from the table and write it down to a file, the data in the pdf-file is corrupted. I tried all kinds of convertation routines (OFT to Binary, OTF to XString, Binary to XString,...)
    Can anybody help me with my problem? I need a pdf from the ArchiveLink table as a file on the filesystem.
    Thank you for your help!
    Best regards,
    Markus

    Hello Otto!
    thanks for your help. I compared the input- und the output-data now and discovered, that the data is identically. The problem which causes my problem, lies in the writing of the data into the file by dataset.
    First, I extract my pdf binary data from database table with the following function module.
    CALL FUNCTION 'SCMS_AO_TABLE_GET'
            EXPORTING
              arc_id       = ls_toa01-archiv_id
              doc_id       = ls_toa01-arc_doc_id
              comp_id      = 'data'
            IMPORTING
              length       = filesize
            TABLES
              data         = lt_data
            EXCEPTIONS
              error_http   = 1
              error_archiv = 2
              error_kernel = 3
              error_config = 4
              OTHERS       = 5.
          IF sy-subrc <> 0.
            RAISE error_retrieving_file.
          ENDIF.
    The result of this operation is stored in lt_data and seems to be correct. I compared the filesize of a pdf which I downloaded from GUI and lt_data. The size is exactly the same amount of bytes.
    This is the coding part which doesn't work properliy is the following:
          OPEN DATASET lv_pdf FOR OUTPUT IN BINARY MODE.
          IF sy-subrc = 0.
          LOOP AT lt_data INTO ls_data.
            transfer ls_data TO lv_pdf.
          ENDLOOP.
          ELSE.
            RAISE error_writing_file.
          ENDIF.
          CLOSE DATASET lv_pdf.
    When the data is written into the dataset, the resulting file is corrupted in a certain way. I compared the binary content of both files, the correct one and the file created with the dataset part and discovered, that the data is identically. Only some line breaks are different. The result of this little differences is a blank pdf file instead of the correct one with text. Seems like really every single bit position has to be identically to the working pdf. If there is one space in the file too much or one line break, the pdf is corrupted.
    Can anybody help me and describe how to create a pdf file out of an internal table?
    Best regards,
    Markus

  • \n is not working by the time writing text into file ...

    Hi,
    I am reading each line from file and writing into another file ...
    It is writing continously in the file even if i use \n for new line ...
    Why "\n" is not working by the time writing text into file ...
    Here is my code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Test11{
    private BufferedReader data;
    private String line=null;
    private StringBuffer buf= new StringBuffer();
    private BufferedWriter thewriter=null;
    private File file=null;
    private FileReader fr=null;
    private String inputLocation="c:\\test14.txt";
    public Test11(){ }
    public void disp(){
    try {   
    file=new File(inputLocation);
    fr = new FileReader(file);
    data = new BufferedReader(fr);
    while ((line = data.readLine()) != null) {
    buf.append(line + "\n");
    String text=buf.toString();
    thewriter = new BufferedWriter(new FileWriter("c:\\test15.txt"));
    thewriter.write(text);
    buf=null;
    thewriter.close();
    } catch(IOException e) { System.out.println("error ==="+e ); }
    public static void main(String[] args) {
    Test11 t=new Test11();
    t.disp();
    System.out.println("all files are converted...");
    I used "\n" after reading each line .. i want output file also same as input file ... how do i break each line by the time writing into text file .. "\n" is working in word pad but now working in notepad ... in note pad i am getting some thing like rectangle insted of "\n" ....
    Any help please .....
    thanks.

    \n works just fine, and every text editor in the world except Notepad understands that it is supposed to be a line-ending character. You don't have a problem, except in your choice of text editor. If somebody is forcing you to use Notepad then you'll have to output "\r\n" instead.

  • Pls help.JSP: I could not store Chinese characters into files.

    Hi experts,
    I have this problem of cant store chinese characters into files(eg. .txt and .properties). I am adding
    these chinese text through a JSP website form....After i key in chinese characters in the textboxes
    in the website and sumbit the results, my chinese characters turned into ASCII or rather garbage in
    the files.
    Is there any way i can get the exact chinese characters i entered in the webite into the files?
    Need urgent assistance here.
    Thanks
    <%@ page contentType="text/html; charset=big5" %>
    <html>
    <head>
    <title>Confirmation</title>
    <meta http-equiv="Content-Type" content="text/html; charset=big5">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    </head>
    <%@ page language="java"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.lang.Integer.*"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.sql.ResultSet.*"%>
    <%@ page import="javax.servlet.*"%>
    <%@ page import="javax.servlet.http.*"%>
    <%@ page import="java.text.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.net.URL"%>
    <%
    //getting attributes from previous page form
    //At this point, chinese characters r retrieved
    //Ascii/garbage displayed for text when retrieved from previous page.
    String gameName=request.getParameter("name");
    String encode=request.getParameter("encode");
    String gameType=request.getParameter("type");
    String info=request.getParameter("description");
    int check=0;
    int nextGameID;
    String temp="";
    String langCode="";
    //establish connection
    Connection con = null;
    try {
    Class.forName("org.postgresql.Driver");
    con = DriverManager.getConnection("jdbc:postgresql://172.20.134.110:5432/smsINTFET" , "postgres",
    "postgres");
    catch(ClassNotFoundException e) {
    out.println("Could not load the driver: "+e.getMessage());
    catch(SQLException e) {
    out.println("SQLException caught in relax db: "+ e.getMessage());
    Statement stmt = null;
    ResultSet rs = null;
    ResultSet ps = null;
    String strSQL = "";
    String strSQL2 = "";
    String tempCat = "";
    strSQL="SELECT gamename FROM cp_games order by gameid;";
    try {
    stmt = con.createStatement();
    rs = stmt.executeQuery(strSQL);
    stmt.close();
    catch(SQLException e) {
    out.println("SQLException caught: "+ e.getMessage());
    while(rs.next())
    check=0;
    temp=rs.getString("gamename");
    if(temp.equalsIgnoreCase(gameName))
    // there is similar record in database
    check=1;
    break;
    else
    check=0;
    if(check==0)
    %>
    <body background="button/bkgd.jpg" bgproperties="fixed">
    <p><b><font size="30pts" face="Monotype Corsiva">Confirmation</font></b></p>
    <HR style="WIDTH: 500px; COLOR: blue; HEIGHT: 3px">
    The following information has been added.
    <table width="75%" border="0" cellspacing="0" cellpadding="2">
    <%
    String strCat="";
    strCat="INSERT INTO cp_games(gamename,description,encode) values('"+gameName+"','"+info+"','"+encode+"');";
    stmt = con.createStatement();
    stmt.executeUpdate(strCat);
    System.out.println("Successful inserted category");
    stmt.close();
    //setting language
    if(encode.equals("ascii"))
    langCode = "US";
    if(encode.equals("ms950"))
    langCode = "TW";
    if(encode.equals("ms936"))
    langCode = "CN";
    strSQL2="SELECT gameid FROM cp_games where gamename = '"+gameName+"';";
    try {
    stmt = con.createStatement();
    ps = stmt.executeQuery(strSQL2);
    stmt.close();
    catch(SQLException e) {
    out.println("SQLException caught: "+ e.getMessage());
    ps.next();
    nextGameID=ps.getInt("gameid");
    out.println("<B>The game number : </B>" + nextGameID);
    %>
    <tr>
    <td><B>Game added: </B><%=gameName%>
    </td>
    </tr>
    </table>
    <%
    String newFile="G:\\home\\smsGamesINTV2\\colorGame\\propertiesFiles\\FET\\CP_Game"+nextGameID+"_"+encode+"_"+langCode+".properties";
    try
    {               //begin file
    PrintWriter outFile=null;
    //create a new file and write the initial settings to file
    outFile=new PrintWriter(new FileOutputStream(newFile,true));
    outFile.println("game_intro="+nextGameID+")"+gameName+" - "+info);
    outFile.println("");
    outFile.println("game_title="+gameName);
    outFile.println("");
    outFile.println("game_type="+gameType);
    outFile.println("");
    outFile.println("qns_no=0");
    outFile.println("");
    outFile.println("ana_no=0");
    outFile.close();
    }//end file
    catch(IOException e)
    out.println("File Create Error");
    else // no match found
    out.println("Game,"+temp+ " already added");
    %>
    </body>
    </html>

    try to add this code under this line:
    <%@ page contentType="text/html; charset=big5" %>
    <% response.setContentType("text/html; charset=big5"); %>
    I have faced the problem like yours and it works fine for me. Try and see.

Maybe you are looking for