D:\Sam\InterviewsMaterial\SiteWorx\SiteWorxTest\src\java\multithread_reader_services\WriterClass.java
 1 /*
 2  * To change this template, choose Tools | Templates
 3  * and open the template in the editor.
 4  */
 5 package multithread_reader_services;
 6 
 7 /**
 8  *
 9  * @author sameldin
10  */
11 public class WriterClass 
12 {
13     
14     private int startIndex  = 0;
15     private int lastIndex   = 0;
16     
17     /** Creates a new instance of WriterClass */
18     public WriterClass(int startIndex, int lastIndex) 
19     {
20         this.startIndex = startIndex;
21         this.lastIndex  = lastIndex;
22     }
23     /*
24      *
25      */
26     public synchronized int write10bytes(byte [] targetByteArray,  byte [] passedReadData)
27     {
28         if(     (null == passedReadData)
29             &&  (null == targetByteArray)
30         )
31             return(MultithreadConstants.ERROR);
32         if(startIndex > lastIndex)
33             return(MultithreadConstants.ERROR);
34         int endLoopIndex = startIndex + MultithreadConstants.MAX_SIZE;
35         if(endLoopIndex > targetByteArray.length)
36             endLoopIndex = targetByteArray.length;
37         int index = 0;
38         for(int loop = startIndex; loop < endLoopIndex; loop++)
39         {
40             targetByteArray[loop] = passedReadData [index];
41             index++;
42         }
43         startIndex += MultithreadConstants.MAX_SIZE;
44         return(MultithreadConstants.SUCCESS);
45     }   
46 }