Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:12:48+00:00 2026-06-05T17:12:48+00:00

I have the following piece of code and in the j for loop the

  • 0

I have the following piece of code and in the j for loop the out.write() only write in j == 0, then the bytesThisWritten is 0.

    boolean append = true;
    FileChannel out = new FileOutputStream(dirToSave + fileName, append).getChannel();
    ByteBuffer dataBuffer = ByteBuffer.allocate(ScanDataStructConstants.NUM_DETECTORS * 4);
                dataBuffer.order(ByteOrder.LITTLE_ENDIAN);
                FloatBuffer floatBuffer = dataBuffer.asFloatBuffer();
                long bytesThisWritten = 0;
                for(int i = 0; i < ScanDataStructConstants.NUM_VIEWS_PER_ROTATION; i++)
                {
                    if(!taskWorker.isCancelled())
                    {
                        taskWorker.setTaskProgress(i); 
                        //write auxHeader
                        AuxHeader auxHeader = auxHeaderArray.getOneAuxHeader(i);                    
                        byteWritten = byteWritten + out.write(auxHeader.getJavoAuxHeader().getCmdByteBuffer()); 
                        System.out.println("DataMgr write auxHeader i=" + i + ", byteWritten=" + byteWritten);

                        //write data                               
                        for(int j = 0; j < ScanDataStructConstants.NUM_ROWS; j++)
                        {                           
                            if(!taskWorker.isCancelled())
                            {
                                float[] oneRow = scanDataArray.getOneRowDataFromAView(i, j);                           
                                floatBuffer.rewind();
                                floatBuffer.put(oneRow);
                                bytesThisWritten = out.write(dataBuffer);
                                byteWritten = byteWritten + bytesThisWritten;
                                if(i == 0)
                                {
                                    System.out.println("DataMgr write data i,j=" + i + "," + j + 
                                            ", bytesThisWritten=" + bytesThisWritten + 
                                            ", byteWritten=" + byteWritten + 
                                            " oneRow.size=" + oneRow.length + 
                                            ", oneRow[0]" + oneRow[0]);
                                }
                            }
                            else
                            {
                                status = ReturnStatusEnum.CANCELED_FAILURE;
                                break;
                            }
                        }
                    }
                    else
                    {
                        status = ReturnStatusEnum.CANCELED_FAILURE;
                        break;
                    }
                }

For the print out I know the source data is not empty:

DataMgr write auxHeader i=0, byteWritten=4256
DataMgr write data i,j=0,0, bytesThisWritten=3584, byteWritten=7840 oneRow.size=896, oneRow[0]-0.012269974
DataMgr write data i,j=0,1, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.012150764
DataMgr write data i,j=0,2, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.0056562424
DataMgr write data i,j=0,3, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.006008148
DataMgr write data i,j=0,4, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.0064029694
DataMgr write data i,j=0,5, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.010842323
DataMgr write data i,j=0,6, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.01802063
DataMgr write data i,j=0,7, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.0023899078
DataMgr write data i,j=0,8, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.0068216324
DataMgr write data i,j=0,9, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.005973816
DataMgr write data i,j=0,10, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.012469292
DataMgr write data i,j=0,11, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.013271332
DataMgr write data i,j=0,12, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]6.542206E-4
DataMgr write data i,j=0,13, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.008749008
DataMgr write data i,j=0,14, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.012054443
DataMgr write data i,j=0,15, bytesThisWritten=0, byteWritten=7840 oneRow.size=896, oneRow[0]-0.008696556

In the i for-loop it seems work but only in j loop it only write once. The FileChannel is in append mode and channel is not closed within i loop. Anything wrong with my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:12:49+00:00Added an answer on June 5, 2026 at 5:12 pm

    change j loop to the following will resolve this issue. it seems the FloatBuffer has some special property.

    for(int j = 0; j < ScanDataStructConstants.NUM_ROWS; j++)
                        {                           
                            if(!taskWorker.isCancelled())
                            {
                                float[] oneRow = scanDataArray.getOneRowDataFromAView(i, j);                              
                                dataBuffer.rewind();
                                FloatBuffer floatBuffer = dataBuffer.asFloatBuffer();
                                floatBuffer.put(oneRow);
                                bytesThisWritten = out.write(dataBuffer);
                                bytesWritten = bytesWritten + bytesThisWritten;
                                if(i == 0)
                                {
                                    System.out.println("DataMgr write data i,j=" + i + "," + j + 
                                            ", bytesThisWritten=" + bytesThisWritten + 
                                            ", byteWritten=" + bytesWritten + 
                                            " oneRow.size=" + oneRow.length + 
                                            ", oneRow[0]" + oneRow[0]);
                                }                               
                            }
                            else
                            {
                                status = ReturnStatusEnum.CANCELED_FAILURE;
                                break;
                            }
                        }
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following piece of code : public Hashmap<String,String> tempmap = new HashMap<String,String>(); and
I have the following piece of code: private Dictionary<object, object> items = new Dictionary<object,
I have the following piece of code: actor { loop { react { case
i have following piece of code with me iam spliting the words using only
I have the following piece of code that runs in a loop. public void
I have following piece of code: It compiles without problems under gcc-3.4, gcc-4.3, intel
I have the following piece of code that takes in some words, stores them
I have the following piece of code in my Model: public function getSite() {
I have the following piece of code where i am concatenating events to the
I have the following piece of code which outputs a long article: <?php the_content();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.