Question about writing out different types...

hi, i have a need to write out records that correspond to the following format:
String, 25 bytes
long, 8 bytes
long, 8 bytes
int, 4 bytes.
for the long and int types i need to write out the actual bytes of these
numbers, NOT their string representation. I have to write this out quite often
in my program, and it is being written to a file so I would like to buffer it. The
problem is, I don't know how to do that.
I would like to be able to get the above 4 data elements and append them to
a byte array. Is there an easy/fast way to do this?
I really appreciate the help!

For primitives, use a DataOutputStream, my problem is now how to output them, its how to
output a lot of them. if i use
the DataOutputStream (which i am currently doing), i
have to make these calls
over and over:
               DOS.write(/*some String*/);
               DOS.writeLong(/*some long*/);
               DOS.writeLong(/*some long*/);
               DOS.writeInt(/*some int*/);but in my program i have to call this, literally,
millions of times. I ran a profiler
on this program and found that most of my time is
spent in this function. Either it's spent in converting the values to bytes, or it's spent in writing those bytes to disk.
I doubt you'll be able to significanly speed up the conversion to bytes. If so, I don't know how.
You might be able to speed up writing the bytes to disk. If you're not using a BufferedOutputStream around your OOS or DOS, you should be.
Side note: I think you can actually use OOS for both primitives and objects, so if you have a mix of the two, it might be better to just use the one OOS.

Similar Messages

  • Question about changing a file type into another file type

    Hello. This isnt a java question but you guys have been so helpful in the past I hope its ok if I ask this question for a friend.
    How can I import a scriptware file into Screenwriter 2000, or change a .scw file into a .tag file?
    Anyone who can help thanks.

    I know nothing about scriptware or Screenwriter. But, my only advice is to see if Scriptware can export some other file type (not necessarily a .scw file) that Screenwriter can read. Sometimes, when I have two text editors whose native formats are incompatible (like opening a paper typed in a new version of Microsoft Word using an old version of WordPerfect or something), I save the file as an RTF file, rather than in the native format. Maybe something like that applies to your situation, too.
    Hope that helps.
    Jason

  • Some questions about writing rc.d scripts the right way

    Hello everyone,
    I'm setting up an environment and have a number of server daemons that I would like to automate the startup of, so I'd like to write some rc.d scripts for them. Now, I could just go ahead and roll my own but I thought I should try to learn the correct way of doing this.
    I have already read the wiki page (https://wiki.archlinux.org/index.php/Wr … .d_scripts) and have used the example there as a starting point, I have a working script that starts a daemon. However I have some questions...
    How do I handle the case where the daemon's name differs from the running process? Once case I have is to start up a web server for ruby documentation. The process I need to start is "gem server" but what is listed in ps is "ruby ... gem server". Starting works just fine, but when trying to stop it the rc.d script uses "pidof gem" to locate the daemon which fails because there is no such process (it's ruby) so stopping the daemon fails.
    My second query is how to handle multiple daemons that differ only in their arguments. I don't think the rc.d script can handle this. I would like to run several of these "gem servers" for different trees of development.
    I may be better off in this case just writing my own thing to do it.
    Any help and advice appreciated...

    Yeah, look elsewhere.
    find / -name \*.pid
    Edit:  an example:
    PIDFILE=/var/run/named/named.pid
    It's in a subdirectory, so that the user that BIND runs at, has permission to create and remove the pidfile from that directory.
    One thing to bear in mind, when stopping a daemon, is that it might not stop immediately. E.g. lighttpd, when asked to do an orderly shutdown with:
    kill -TERM $(pidof -s /usr/sbin/lighttpd) 2>/dev/null
    Cannot be immediately checked in the initscript. My erm, workaround for that is to just assume that it got the message
    Last edited by brebs (2012-03-07 13:49:17)

  • OK: simple question about video out

    My new mac mini should arrive today. I'm taking it one step at a time but planning down the road as I hope to hook it to my TV for Netflix streaming, Hulu, etc. I've ordered the S-Video adapter so I'll be good there.
    My question: I know that to drive a second monitor (not mirrored) that a third party, usually USB solution is needed. But what if I just want to mirror out to my TV what is shown on the monitor? Will a DVI splitter do the job?

    A splitter will generally not work - or at least that well - because it means the mini will receive two separate signals from the displays indicating conflicting possible settings. It would only then work at resolutions which are common to both displays - typically 640x480 and 800x600.
    What complicates it more in your case is that since you want to drive the TV with the DVI-to-S-Video adapter, if you were to add a splitter before that cable, it would eradicate the S-video component since that is catered for by the adapter alone. And clearly you can't add a splitter after the adapter.
    There is no real, easy way to add dual display use to a mini, but the recently released USB adapter and the Matrox dual-head-to-go are probably the most viable. Even then, in as far as the former, the USB display will be relatively slow, and in the latter, you will be limited to what amounts to two 1024x768 screens - in effect, your TV and a 15" LCD. It is also not clear whether the Matrox unit passes the S-video component of the mini's output, meaning that if it does not, it can also not be used if a TV is being connected by composite or S-video.

  • Question about zeroing out data...

    I'm currently zeroing out my Time Capsule's hard drive and starting fresh with backing up. I started doing a 7 pass method the other day, but figured it was overkill and bad on the hard drive, so I stopped it a quarter of the way through pass 2. Does this mean that at least the one full pass was done successfully? Also, to make sure that everything is truly zeroed out, I started a one-time zero out erase. So, does this mean, then, that my TC truly has been zeroed out twice for starting over on my backups?
    And, while we're on the subject, I did some research on zeroing out data. Most people are in agreement that doing one pass is good enough. Apple recommends twice for a fully secure wipe. While researching this, I found that some claim that zeroing out a hard drive during a 7 pass and 35 pass method significantly decreases the lifespan of a hard drive. Is this myth busted or confirmed? Also, is zeroing out data only once already harmful to an HD's lifespan?

    William Boyd, Jr. wrote:
    apple_kmj wrote:
    I'm currently zeroing out my Time Capsule's hard drive and starting fresh with backing up.
    I'll leave to others the answering of your questions, but I have one of my own: What are you hoping to accomplish by zeroing out your Time Capsule's drive? I would only consider that useful if I were planning to sell or otherwise dispose of a Time Capsule.
    I heard that it's the best way to go if you have a lot of data synced and you don't want to individually pick out data to delete. Also, backups were taking a while, and I noticed that my Time Machine had nothing on it even though my Time Capsule showed as having almost 80 GB of data backed up. So, just to eliminate any potential problems, I zeroed out data and started over again.

  • Question about writing a web server

    I was asked to write a simple Web server that responds to HTTP requests received on port 808
    It has the following features:
    1.a request for an HTML document or image file should generate a response with the appropriate MIME type
    2.a request for a directory name with a trailing / should return the contents of the index.html file in that directory (if it exists) or else a suitably formatted HTML listing of the directory contents, including information about each file
    3.a request for a directory name without a trailing / should generate an appropriate Redirect response
    4.a request for a non-existent file or directory should generate an appropriate error response
    5/the Web server should be multi-threaded so that it can cope with multiple
    how to do it?
    may anyone help me please?

    As a startert for ten, try this that I had lying around form a previous
    forum response.
    java -cp <whatever> Httpd 808
    and connect to http://localhost:808 to get an eye-full.
    If you should use this for anything approacing a commercial
    purpose, I will, of course, expect sizable sums of money to be
    deposited in my Swiss bank account on a regular basis.
    Darn it! I'm serious!
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Httpd
         implements Runnable
         private static String HTTP_400=
              "<HTML><BODY><H2>400 Bad Request</H2></BODY></HTML>";
         private static String HTTP_403=
              "<HTML><BODY><H2>403 Forbidden</H2></BODY></HEAD>";
         private static String HTTP_404=
              "HTML><BODY><H2>404 Not Found</H2></BODY></HTML>";
         public static void main(String[] argv)
              throws Exception
              new Thread(new Httpd(Integer.parseInt(argv[0]))).start();
         private int mPort;
         public Httpd(int port) { mPort= port; }
         public void run()
              try {
                   ServerSocket listenSocket= new ServerSocket(mPort);
                   System.err.println("HTTPD listening on port " +mPort);
                   System.setSecurityManager(new SecurityManager() {
                        public void checkConnect(String host, int p) {};
                        public void checkCreateClassLoader() {};
                        public void checkAccess(Thread g) {};
                        public void checkListen(int p) {};
                        public void checkLink(String lib) {};
                        public void checkPropertyAccess(String key) {};
                        public void checkAccept(String host, int p) {};
                        public void checkAccess(ThreadGroup g) {};
                        public void checkRead(FileDescriptor fd) {};
                        public void checkWrite(String f) {};
                        public void checkWrite(FileDescriptor fd) {};
                        // Make sure the client is not attempting to get behind
                        // the root directory of the server
                        public void checkRead(String filename) {
                             if ((filename.indexOf("..") != -1) || (filename.startsWith("/")))
                                  throw new SecurityException("Back off, dude!");
                   while (true) {
                        final Socket client= listenSocket.accept();
                        new Thread(new Runnable() {
                             public void run() {
                                  try {
                                       handleClientConnect(client);
                                  catch (Exception e) {
                                       e.printStackTrace();
                        }).start();
              catch (Exception e) {
                   e.printStackTrace();
         private void handleClientConnect(Socket client)
              throws Exception
              BufferedReader is= new BufferedReader(
                   new InputStreamReader(client.getInputStream()));
              DataOutputStream os= new DataOutputStream(client.getOutputStream());
              // get a request and parse it.
              String request= is.readLine();
              StringTokenizer st= new StringTokenizer(request);
              if (st.countTokens() >= 2) {
                   String szCmd= st.nextToken();
                   String szPath= st.nextToken();
                   if (szCmd.equals("GET")) {
                        try {
                             handleHttpGet(os, szPath);
                        catch (SecurityException se) {
                             os.writeBytes(HTTP_403);
                   else
                        os.writeBytes(HTTP_400);
              else
                   os.writeBytes(HTTP_400);
              os.close();
         private void handleHttpGet(DataOutputStream os, String request)
              throws Exception
              if (request.startsWith("/"))
                   request= request.substring(1);
              String path= request;
              File f;
              if (request.endsWith("/") || request.equals("")) {
                   path= request +"index.html";
                   f= new File(path);
                   if (!f.exists()) {
                        if (request.endsWith("/"))
                             path= request.substring(0, request.length()-1);
                        else if (request.equals(""))
                             path= ".";
                        f= new File(path);
              else
                   f= new File(path);
              if (!f.exists())
                   os.writeBytes(HTTP_404);
              else if (f.isFile())
                   getFile(os, f);
              else if (f.isDirectory())
                   getDirectory(os, f);
         private void getDirectory(DataOutputStream os, File f)
              throws Exception
              getDirectory(os, f, "");
         private void getDirectory(DataOutputStream os, File f, String prefix)
              throws Exception
              StringBuffer szBuf= new StringBuffer();
              String szTitle= "Index of /";
              if (!f.getPath().equals("."))
                   szTitle= "Index of " +f.getPath().substring(prefix.length());
              szBuf.append("<HTML><HEAD><TITLE>");
              szBuf.append(szTitle);
              szBuf.append("</TITLE></HEAD><BODY><H1>");
              szBuf.append(szTitle);
              szBuf.append("</H1><BR><PRE>");
              szBuf.append(
                   "Name                              Last Modified              Size<HR>");
              String dir= "";
              if (!f.getPath().equals(".")) {
                   dir= f.getPath() +"/";
                   szBuf.append("<A HREF=\"..\">Parent Directory</A><BR>");
              java.text.SimpleDateFormat fmt=
                   new java.text.SimpleDateFormat("EEE MMM d yyyy hh:m:ss");
              String[] list= f.list();
              for (int i= 0; i< list.length; i++) {
                   String path= list;
                   File d= new File(dir + path);
                   if (d.isDirectory())
                        path += "/";
                   szBuf.append("<A HREF=\"");
                   szBuf.append(path);
                   szBuf.append("\">");
                   szBuf.append(path);
                   szBuf.append("</A>");
                   for (int j= path.length(); j< 34; j++)
                        szBuf.append(" ");
                   if (d.isDirectory())
                        szBuf.append("[DIR]");
                   else {
                        szBuf.append(fmt.format(new java.util.Date(f.lastModified())));
                        szBuf.append(" ");
                        szBuf.append(formatFileSize(d.length()));
                   szBuf.append("<BR>");
              szBuf.append("</PRE></BODY></HTML>");
              byte[] buf= szBuf.toString().getBytes();
              os.write(buf,0,buf.length);
         private String formatFileSize(long size)
              if (size < 1024)
                   return "" +size;
              if (size < (1024*1024))
                   return (new Float(size/1024).intValue()) +"K";
              if (size < (1024*1024*1024))
                   return (new Float(size/(1024*1024)).intValue()) +"M";
              if (size < (1024*1024*1024*1024))
                   return (new Float(size/(1024*1024*1024)).intValue()) +"G";
              return "Massive!";
         private void getFile(DataOutputStream os, File f)
              throws Exception
              DataInputStream in= new DataInputStream(new FileInputStream(f));
              int len= (int) f.length();
              byte[] buf= new byte[len];
              in.readFully(buf);
              os.write(buf,0,len);
              in.close();

  • Question about syncing two different iPads on 1 iMac?

    Hey all, I bought two iPad 2's today (both gifts, 1 for my mom and 1 for my dad). Bought it for them because they're probably too old at this stage for me to teach them to use a desktop efficiently. iPad is so easy for them to use the internet and listen to their music which is most important.
    My question is, I don't have an iPad myself nor any iOS devices. Maybe I'll buy an ipad in a few months or so. However I do own the only computer in the house and that's my iMac. I was going to sync both my mom and dad's iPads to my Mac, and put their songs from my iTunes library on their iPads respectively. Will I incure any problems trying to do this?
    I don't want my mom and dad's iPads to be identical and I want to sync different pictures and songs and stuff on their ipads. I want it to be their own individually.
    What steps should I take to do this? I've never really synced any iOS products before but I pick up on this stuff pretty quickly. Made the transition from a Windows desktop to a Mac easily and would do it all over again!

    Have a read here...
    https://discussions.apple.com/message/18409815?ac_cid=ha
    And See Here...
    How to Use Multiple iDevices with One Computer

  • A simple question about c:out and the ADF bindings

    I have a small problem which I can't figure out :-(
    The solution is probably dead easy, but I don't see it ..
    The problem is :
    I have a jsp-file which have the following tags :
    <c:out value="${bindings.EstimatedInterest}" />
    <c:out value="${bindings.RemainingAmount}" />
    And I want to have one more field which just adds these two together.
    But I get this error :
    Attempt to coerce a value of type "oracle.jbo.uicli.binding.JUCtrlAttrsBinding" to type "java.lang.Long" (null)
    Can anyone pls point me in the right direction ?
    With regards, TA

    Hi Thor,
    try this,
    <c:set var="EstimatedInterest" value="${bindings.EstimatedInterest}"/>
    <c:set var="RemainingAmount" value="${bindings.RemainingAmount}"/>
    <c:out value="${EstimatedInterest+RemainingAmount}" />
    oscar

  • Question about Inner/Outer classes

    Hello!
    I'm still preparing for java cert exam and have a question. If I have Outer and Inner classes like this:
    Outer o = new Outer();
    Outer.Inner i = o.new Inner();Does this mean that 'i' has a reference to both Outer and Inner classes. Moreover, does 'i' have a reference to the 'this' of 'o'?
    Thanks,
    Victor.

    "i" doesn't have a reference. "i" is a reference. I think you are trying to express this:
    import java.lang.reflect.*;
    public class Outer {
        class Inner {
            private int foo;
        public static void main(String[] args) {
            Outer o = new Outer();
            Outer.Inner i = o.new Inner();
            for(Field field : i.getClass().getDeclaredFields()) {
                System.out.format("%s %s %s;%n", Modifier.toString(field.getModifiers()),
                    ((Class)field.getGenericType()).getName(), field.getName());
    }

  • Question about uesr-defined data types

    Can anyone help me to answer the question?
    Explain the user-defined data types in Oracle Spatial, and give examples how these data types and their associated operations are used to support
    i.     Storage
    ii.     Indexing
    iii.     Retrieval
    of spatial data.
    thanks!!

    you need to look at the oracle spatial user's guide, which gives most of that information. it is downloadable from otn...

  • Question about filtering a file type on check in?

    I am reading on how to filter file types on check in and I was wondering.  Is it possible to check a file type and pop up a error page in iDoc, or would I have to go the custom component route (and would that need to be java or iDoc)?

    Thanks for the input, but seeing how the setting where I'm going to employ this component for UCM is secure I can't use code I can't read for myself (No offence to the author of that blog or to you).  But yeah I kinda figured making a filter based component would be the best route, but most examples I've found used the intradoc library.  Problem is I can't seem to find the intradoc library to try to write a basic example to see what I'm doing, everything I get is for RIDC (even found a small example on writing a filter for RIDC).  Is this what UCM is using now in 11g?
    Also one thing I felt missing when looking at example code, I get the basic idea of the code itself.  But to employ the componant to work on the check in request would I just include that component in that idoc function for checkin?

  • Hello question about blown out layout and designer

    hello im a web designer....my format is to slice my layout in fireworks....then I bring things into dreamweaver and then place flash files into placed blank spots...........my problem is I notice things get out of line and blown out.....how can i fix this?
    example:---http://sites4sight.com/Zdara/Lounge.html...this is fine in safari and IE?

    Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The helpers over there are more knowledgeable about web page development issues with Firefox. <br />
    http://forums.mozillazine.org/viewforum.php?f=25 <br />
    You'll need to register and login to be able to post in that forum.

  • Question about laying out a maze and buttons

    I am very new to SWING, and I just finally figured out how to draw my maze. I am drawing it on a JPanel, using the layout manager. Then I plop that JPanel onto a JFrame. But now i want to have a program that has the JPanel, which is basically the maze, and two buttons far below, kind of like how a java minesweep game would look. Can somebody give me a hint as to how this is done? Do I have to put another JPanel, that holds this "maze JPanel," and which also holds 2 other places for buttons? Because if I just add the buttons to this JPanel, everythinig will be squished together right? How would a professional program lay this out?

    Well, the idea is you plan your layout ahead of time. The typical look of an application is:
    1) toolbar
    2) main window
    3) statusbar
    This layout suits the BorderLayout perfectly.
    Then take a look at you main window. If you main window consists of a single component then just add it to the center of the BorderLayout. If, however, it consists of multiple components then create a new JPanel add it to the center and determine the best LayoutManager to use. This can be a recursive process.
    So, to answer your question, yes, you would nest layout managers within layout managers (or JPanels within JPanels).

  • Question about working on different computers on a project?

    I'm going to have video footage stored on an external Firewire 800 hard drive and I'm going to work on a project in a lab that has 30 different Macs, so I will not always be working on the same computer.
    Do I need to change any settings each time I get on a new Mac or will the project file always open up the media each and every time I double click on it or open it in CS6?
    Thanks.

    1. When you say you assign a unique drive letter for each external, do you mean you are simply naming the hard drive itself so each of your externals shows up with its own unique name OR are you referring to something else?
    In Windows, all drives are deliniated by "drive letter." This is set in the OS, and is part of that absolute Path, such as Z:\[Project Name]\Video. When I get a new external, I set it's drive letter in the OS of each computer and then add a label to it. In Windows, each HDD, whether internal, or external, has an I.D. number, and if one has set the drive letter, when the OS sees that I.D., it knows what to do. I started with Z:\, and worked backward. As my workstation has a bunch of HDD's, I ran out of drive letters, and just started over. However, that means that I cannot have both of my Z:\ externals hooked up at the same time. That, however, is not a problem, as I have each one marked, and they have unique Projects on them, so I should never need both Z:\'s at the same time. Mac's do things a bit differently, and I am certain that I would get it wrong, so will let a Mac-user discuss that with you.
    Again on Windows, if one has NOT set the drive letter, then the OS will assign one, and that will depend on the existing drive letters used on the system, and the order that any external devices are plugged in and turned ON. As a for instance, let's say that I plug in that Z:\, into a computer where it has not yet been set to Z:\, it will usually be assigned the next drive letter, for that computer, so it might be F:\, and then my absolute Paths are broken, since they point to Z:\.
    Good luck,
    Hunt

  • 2 Skype #'s, 1 Account: Question About Calling Out

    Hi folks - I am needing a 2nd Skype # for business in a 2nd area code. Same biz, just a different location. From my research it seems that having both #'s under 1 account could work. I don't really need to know which # was called. However... I do need to be able to choose which # to call out on. One area code for one region and the other # for the other location. I use Skype on my iPad and Android phone. Will I be able to choose which # to make a call from on both of these devices? Thanks much.
    Solved!
    Go to Solution.

    When two Skype Numbers are associated with the same account, it is possible to control which number will be used for outgoing Caller ID purposes
    Toggling between these numbers is possible in your account settings, but it is not particularly convenient to do this on an ongoing basis, especially since the setting is not available in profile settings under Android
    It is also possible set up Caller ID so that the number that corresponds to the country code of the number you are calling is displayed, but that won't work when the Skype Numbers are for different area codes in the same country
    Another way to address this issue is to use 2 Skype accounts, and get a Skype Number for each Skype Name
    It is possible to simultaneously run multiple instances of the Skype client under Windows and Linux (and I think OS X too), but, unfortunately, not on smartphones or tablets
    Regards,
    Neil

Maybe you are looking for