i am having a below piece of code in my worker thread. In my output i am getting xml records from the database. I'm sending this output to a input stream & finally to a sax parser.My query is, before sending to the parser i need to store the input stream in buffer. The buffer should store 1000 records. For every 1000 records the parser should be called from buffer.
while (orset.next()) {
output = orset.getString("xmlrecord");
writeCount++;
InputStream in = new ByteArrayInputStream(output.getBytes("UTF-8"));
InputStream inputStream = new ByteArrayInputStream(output.getBytes("UTF-8"));
Reader reader = new InputStreamReader(inputStream,"UTF-8");
I have two programs that I'll post below, one is a Server and the other is a Client. The ChatServer runs once and many clients can run ChatClient from separate computers and talk together in their GUI's. The the client program comes with two buttons, one that's simulates the sending of a message to a single user ; "Send Message To User", and one that just generally sends a message ; "Send Message To All". Although now the Clients on the server seem to be able to selectively send messages to an individual by giving the recipient name, all the clients can see that message, which is not exact what I am aiming for. What I am going for is having the "Send Message To User" button click to send a message to the named user without all other users seeing the message.
Now I have tried thing like having various input output streams and trying to connect those, but no luck. Tried fiddling with having the names arraylist directing the messages to one client versus all but that did not work out either. How I what I would need to do to go about doing this?
The assignment is to create a program that accepts entries from a user for 3 variables then saves the data to a file. There are other programs that use the file created. One program displays the non-default records. The next program allows the user to enter the id for the employee and displays the first and last name for that id number. The last program allows the user to enter a first name. It then displays all id numbers and last names for records with that first name.
Given the above situation, I am stuck on creating the first program. I can make the text file and write the information to it. However, when the file is created, a space is placed in between each entry for some reason. I cannot figure out how to get rid of this space so that I can display the appropriate records for the remaining programs. Below is the code and a view of my problem.
import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.*; import java.io.*; import static java.nio.file.StandardOpenOption.*; import java.util.*; public class WriteEmployeeList {
[Code] .....
The values for nameFormat and lnameFormat are 10 spaces. This is how the book told me to make sure everything is uniform and searchable. The file contents look like this when viewed in notepad.
Due to compatibility reasons, I need to be able to store a random C buffer inside of a Java String. THis means that the Java String should contain the exact same buffer information (i.e. byte sequence) as the original C buffer. How would I do that?
All the functions I found will always somehow code/decode the C buffer, and modify its content depending on the selected encoding.
I need to do this inside JNI. Following is what I have:
Java Code:
unsigned char* cBuffer=getCBuffer();
// Transfer the C buffer to s: jstring s=NULL; if (env->EnsureLocalCapacity(2) >= 0) { jbyteArray bytes = env->NewByteArray(signalLength); if (bytes != NULL)
I have the following code which always gives me java heap space error because of line number 65 due to string buffer append method in this line, I don't know why?
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import samy.*; import java.util.Scanner; public class InfixToPostfix { OrderedList list = new OrderedList(); Scanner input = new Scanner(System.in); public StringBuffer postfix = new StringBuffer();
I'm writing a simple application, that provides a Swing GUI to a bounded-buffer problem. The application is composed by:
- Main.java: it creates a map of four threads (four instances of the class MyThread). Also it creates a shared database (an instance of the class Database) between the four threads.
- MyThread.java: it's an extension of Thread, and it shows a Swing GUI associated to this thread. Each thread is associated a GUI.
- GUI.java
- Database.java: it's an extension of ArrayList and and it can contain a maximum of five elements. An element is an instance of the class User. Also it implements put() and extract() method consistent with the algorithm of bounded-buffer problem.
- DatabaseException.java: it's a simple message.
- User.java
public class Main { public static void main(String[] args) { Database db = new Database(); Map<String, Thread> tdg_m = new HashMap(); for (int i = 1; i <= 4; i++) { tdg_m.put("T" + i, new MyThread(db));
[Code] .....
The issue is the following. When the database is full, and i try to put an element, the GUI freezes. The same problem occurs when I try to extract an element from the empty database.
Normally I would just implement a circular buffer and be happy but there's a fundamental problem with that.OK, so I'm working on a piece of cheap Android hardware that's being used for demo purposes. One of the problems, primarily because it's cheap (imo) is that the screen input is not clean and is interfering with the UI experience. Specifically when gliding your finger, the result is quite non linear.
I know that's not the best drawing but it sort of explains the problem to a degree. In reality, it's probably a bit smoother than that, but there is still noisy data getting in, and the problem is it causes the UI to be jittery at times.
I would like to smooth this using something like a Circular Buffer. Now I figured the best way to do this would be to store the last 4 float inputs and then effectively calculate the next value based on an average, so say our input was this:10, 15, 20, 25 and 35 is the current input.
15 - 10 = 5 20 - 15 = 5 25 - 20 = 5
Then for the next value, 35 - 25 = 10. 10 + (3 * 5) = 25 / 4 = 6.25...Then adding 6.25 to the previous value resulting in this: 10 15 20 25 31.25 which would appear theoretically smoother. However I'm struggling to work out in my head the best way to implement such a function.
So I have this file in which has a few sentences on a single line. What I need to be able to do is read the file and then take each word and create a token out of it. Then what it does is it selects the first letter of every 5th word, uppercase it, and then allow me to use append it via a stringbuffer object to create a word out of it.
I know I'll need to use a string tokenizer but I'm not sure how to do so in a way that makes each word separate and how to tell it to only hit the 1st letter of every 5th word.
Here's what I've come up with so far, but I'm currently at a loss at what to do and my textbook/documentation is just not working.
Java Code:
String line; // The line we read from the file. char letter; // The first letter of each 5th word. String sw; // The completed string. public static void main (String [] args)throws IOException {
My program has to take the given bar code, check for correct characters and correct length, then it has to give the corresponding zip code. It instead just spits out 0's. I can't find where the problem is.
public class GavinBarnesrealHw7 { public static void main(String[] args) { boolean length; boolean good_char;
I've recently tried to write a file parser for the .x3d file type as it's one of the few 3d model types I can find written in easy to understand (and interpret) English. While it technically does work (or what I have so far), the issue is that it takes far too long (17 minutes) to parse just a part of the file (the vertices of the model).This is the code for the object itself:
import java.io.*; import com.sun.j3d.utils.geometry.*; import javax.media.j3d.*; import javax.vecmath.*; public class ModelLoader { BranchGroup object = new BranchGroup(); BufferedReader reader; String line = "start";
[code]....
Anyway, here are some observations I've made about the file:
-The line in the file itself that contains all the vertices is all one giant string according to the file. -There are apparently 18,000 vertices in all (according to the command at line 18). -Unless Netbeans automatically terminates infinite loops after a certain amount of time, it is most definitely NOT an infinite loop as I have seen the program terminate on its own (after 17 minutes, though).
I had a theory that maybe organizing each vertex into its own line and then having the program switch to the next line when it's done reading that vertex might make the program run faster, but I'm not sure why it would, so I thought I'd come here in case that theory turned out to be a dead end.
There is JAVA Sql parser which supports all ASCII characters in my project. This parser fails when the query contains multi byte characters.We have used UTF8 encoding. How to handle multi byte chars.
how to use SAX Parsers. I've looked at a few tutorials and have the generals down. I have an xml file that the parser is trying to read. As you see below, at the start of each element, I add the tag to an arrayList of the tags. I create a stringBuilder to capture the text between tags, this won't work unless it occurs at the end of an element. If it occurs at the start, it never gets the chance to read the text.
This is where the problem occurs. For nested tags, like project, it reads the last nested tags' text and stores it in the text arrayList. Project may be the first indexed tag in the tags arrayList, but project's text is the fourth indexed element of the text arrayList. So when my test print the arrayLists by index, it gets thrown off. I want over tags to store a blank space in the text array, and at the same index of the tag its associated with. How would I do this?
I've tried overwriting the text arrayList, but couldn't get my logic thought out for how to determine if a tag was nested. I always ended up overwriting blank space to each element.
I have a program that is a XML-parser, and it works fine when I'm running it from NetBeans. But when I create a JAR-file and run the very same program, it cannot find the xml file. Consider this small program that addresses my problem:
I'm starting to use AbstractTableModel to customize a JTable model. The problem appears when you add a record from a ResultSet to JTable object.
I've managed to insert records, but empty, I need that for every column I can see the data is there.
Leave some code I have been writing ... the method to insert records in JTable is called "insertEmptyRow" (for now).
I need some opinion that can make changes to the code of this method so you can get to see all the data in a record.
MyFirstModel:
public class TablaModeloPrincipal extends private String algo; private int numRegTabla; //Agrego las columnas que quier tener en el model private String[] columnNames = {"DNI", "Nombre", "Edad", "Dirección", "Empresa", "Contacto"}; Vector<String[]> clientes = new Vector<String[]>() ; public ResultSet buscarResultset() throws SQLException{ ResultSet rs=null;
I am working on a project and for one step, I need to load an array (which in this case, students[]), with the records in another file.
So, should I used the try, catch method?? I am just not sure about the array. I know how to read from a file, but, I didn't get the idea of loading an array.
I am having some difficulty adding a new item to the HashTable when a collision occurs. We can only use the basic utilities to code this, so we are coding a HashTable by hand. We have an array of length of 10, which each index holds or will hold a Node for a Linked List.
The code hashes fine, adds the item, but the problem exists when adding items that already been hashed. The project is much bigger, but this is the engine behind the rest, and I figured I would tackle this first.
The items we are adding are objects which are states containing different information, we hash based on the ASCII sum % tableSize.
Here is the code I am testing with to add items:
HashTable ht = new HashTable(10); State az = new State("Arizona","AZ","W",2,"Y",2); State fl = new State("Florida", "FL", "F", 2, "X", 2); State hi = new State("Hawaii", "HI", "H", 3, "Z", 1); State al = new State("Alabama", "AL", "A", 5, "W", 0); ht.insert(hi);
So I am calling this method several times and trying to write multiple records to a file. Problem is that every time I call the method it overwrites the file from before and doesn't add it.
public void fileWriterMethod() throws IOException{ RandomAccessFile raf = new RandomAccessFile(filename, "rw"); raf.writeInt(id); raf.writeInt(existingMileage); raf.writeInt(gasCost); raf.writeInt(ndays); raf.writeInt(rate);
I am reading records from a txt file and storing it into an array
import java.util.*; import java.io.*; public class PatientExercise { //patients exercise time public static void main (String[]args) throws IOException{ Scanner in = new Scanner(new FileReader("values.txt")); double [] patientTimeRecords = new double [300]; int noExerciseCount=0, numPatients =0; double highest=0, lowest=0, avg=0, totalTime=0;
[Code] ....
However an error msg keeps popping up:
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:907) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextDouble(Scanner.java:2456) at pastpapers.PatientExercise.main(PatientExercise.ja va:44)
line 44 is:patientTimeRecords[i]= in.nextDouble();