dear all,
i want to read a mp3 file using java and want to download it in jsp,i want to return byte array or i can only return one byte at a time?.please suggest
Hello all ,
i am using ResourceBundle and i want to give the user an option
to select a language for the GUI.
i want to get a list of all resource files that are under a specific package.
i don't know what resource i will have since this application based on plug-ins
is there an option to ask from java to search all available resources under a package ?
(if no i guess the plug-in should give all available local for it)
thank you all
I am new to java, I have seen in the code at many places where my seniors have declared as
List myList = new ArrayList(); (option1)
Instead of
ArrayList myList = new ArrayList(); (option2)
Can you please tell me why people use Option1, is there any advantages?
If we use option2, do we miss out any advantages or features?
<c:forEach items="${myParams.items}" var="currentItem" varStatus="stat">
<c:set var="myVar" value="<c:out var="myVar" />" />
</c:forEach>
I want to concatenate the values of currentItem.myVar and output it at the end of the loop, problem is I can't figure out how to do this...
(Preferably not using Java)
I am in a need of programatically convert an Word-XML file into a RTF file. It has become a requirement, because of some third party libraries. Any API/Library that can do that?
Actually the language is not a problem because I just need to work done. But Java, .NET languages or Python are preferred.
I am new to java. I was wondering if there is a tool to copy fields and method easily.
E.g if I have
private String foo; // with getter/setters
I should be able to select foo and type bar car in a textbox and the tool should generate fields bar and car with their getter/setters.
Hi, I'm trying to evaluate whether Flex can access binary sockets. Seems that there's a class calles Socket (flex.net package). The requirement is that Flex will connect to a server serving binary data. It will then subscribe to data and receive the feed which it will interpret and display as a chart. I've never worked with Flex, my experience lies with Java, so everything is new to me. So I'm trying to quickly set something simple up. The Java server expects the following:
DataInputStream in = .....
byte cmd = in.readByte();
int size = in.readByte();
byte[] buf = new byte[size];
in.readFully(buf);
... do some stuff and send binary data in something like
out.writeByte(1);
out.writeInt(10000);
... etc...
Flex, needs to connect to a localhost:6666 do the handshake and read data. I got something like this:
try {
var socket:Socket = new Socket();
socket.connect('192.168.110.1', 9999);
Alert.show('Connected.');
socket.writeByte(108); // 'l'
socket.writeByte(115); // 's'
socket.writeByte(4);
socket.writeMultiByte('HHHH', 'ISO-8859-1');
socket.flush();
} catch (err:Error) {
Alert.show(err.message + ": " + err.toString());
}
The first thing is that Flex does a <policy-file-request/>. I've modified the server to respond with:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="192.168.110.1" to-ports="*" />
</cross-domain-policy>
After that - EOFException happens on the server and that's it.
So the question is, am I approaching whole streaming data issue wrong when it comes to Flex? Am I sending the policy file wrong? Unfortunately, I can't seem to find a good solid example of how to do it. It seems to me that Flex can do binary Client-Server application, but I personally lack some basic knowledge when doing it.
I'm using Flex 3.5 in IntelliJ IDEA IDE.
Any help is appreciated.
Thank you!
Let's say I have two entities, Employee and Skill. Every employee has a set of skills. Now when I load the skills lazily through the Employee instances the cache is not used for skills in different instances of Employee.
Let's Consider the following data set.
Employee - 1 : Java, PHP
Employee - 2 : Java, PHP
When I load Employee - 2 after Employee - 1, I do not want hibernate to hit the database to get the skills and instead use the Skill instances already available in cache. Is this possible? If so how?
Hibernate Configuration
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/cache</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<mapping class="org.cache.models.Employee" />
<mapping class="org.cache.models.Skill" />
</session-factory>
The Entities with imports, getters and setters Removed
@Entity
@Table(name = "employee")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
public Employee() {
}
@ManyToMany
@JoinTable(name = "employee_skills", joinColumns = @JoinColumn(name = "employee_id"), inverseJoinColumns = @JoinColumn(name = "skill_id"))
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private List<Skill> skills;
}
@Entity
@Table(name = "skill")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Skill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
}
SQL for Loading the Second Employee and his Skills
Hibernate: select employee0_.id as id0_0_, employee0_.name as name0_0_ from employee employee0_ where employee0_.id=?
Hibernate: select skills0_.employee_id as employee1_1_, skills0_.skill_id as skill2_1_, skill1_.id as id1_0_, skill1_.name as name1_0_ from employee_skills skills0_ left outer join skill skill1_ on skills0_.skill_id=skill1_.id where skills0_.employee_id=?
In that I specifically want to avoid the second query as the first one is unavoidable anyway.
Is there something similar to the Eclipse cleanup rules ((Preferences Java Code Style Clean Up) in NetBeans?
The cleanup rules in eclipse will allow you to clean things up like organizing imports, removing unnecessary casts, adding missing override annotations etc.
Also can you do that on a whole set of classes/packages instead of individual classes?
I just got this Chumby thing for Christmas. I was thinking of writing a StackOverflow widget for it. Does anyone know any caveats to programming this, or especially good things for chumby virgins to know? I have not yet begun to do my research. I guess it's just a Linux device which runs java widgets.
hello
how could we uses junir related methods?
could we launch setuponce from each java test?
if in my test I launch the appli by calling setuponce, is it correct ?
Over the years, I've tried to avoid instanceof whenever possible. Using polymorphism or the visitor pattern where applicable. I suppose it simply eases maintenance in some situations... Are there any other drawbacks that one should be aware of?
I do however see it here and there in the Java libraries so I suppose it has its place? Under what circumstances is it preferable? Is it ever unavoidable?
I'm trying to save a file to a Sharepoint server using JAX-WS. The web service call is reporting a success, but the file doesn't show up.
I used this command (from a WinXP) to generate the Java code to make the JAX-WS call:
wsimport -keep -extension -Xnocompile http://hostname/sites/teamname/_vti_bin/Copy.asmx?WSDL
I get a handle on the web service which I called port using the following:
CopySoap port = null;
if (userName != null && password != null) {
Copy service = new Copy();
port = service.getCopySoap();
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
} else {
throw new Exception("Holy Frijolé! Null userName and/or password!");
}
I called the web service using the following:
port.copyIntoItems(sourceUrl, destUrlCollection, fields ,
"Contents of the file".getBytes(),
copyIntoItemsResult, copyResultCollection)
The sourceUrl and the only url in destUrlCollection equals "hostname/sites/teamname/Tech Docs/Sub Folder".
The FieldInformationCollection object named fields contains only one FieldInformation.
The FieldInformation object has "HelloWorld.txt" as the value for displayName, internalName and value.
The type property is set to FieldType.FILE. The id property is set to (java.util.UUID.randomUUID()).toString().
The call to copyIntoItems returns successfuly; copyIntoItemsResult contains a value of 0 and the only CopyResult object
set in copyResultCollection has an error code of "SUCCESS" with a null error message.
When I look into the "Tech Docs" library on Sharepoint, in the "Sub Folder" there's no file there.
Why wouldn't it tell me what I did wrong? Did I just miss a step?
Update (Feb 26th, 2011)
I've changed my FieldInformation object's displayName and internalName properties to be "Title" as suggested. Still no joy, but a step in the right direction.
After playing around with the urls for a bit, I got these results:
With both the sourceUrl and the only destination URL equivalent, with no protocol, I get the SUCCESS response but no actual document appears in the document library.
With both of the URLs equivalent but with an "http://" protocol specified, I get an UNKNOWN error with "Object reference not set to an instance of an object." as the message.
With the source URL an empty string or null, I get an UNKNOWN error with " Value does not fall within the expected range." as the error message.
Hi,
I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom, but It complains.
The Question is :Is there any way to
use JAXP to parse such documents ??
I have a file containing data such as :
<employee>
<name value="ahmed" > <!-- note, this element is not closed, So it is not well-formed xml-->
</employee>
I'm wondering if anyone is aware of a web-based dos emulator that would allow running dos games through a browser window? Perhaps written in Flash, Silverlight, AJAX, or Java?
Recently I started to use Eclipse's java compiler, because it is significantly faster than standard javac. I was told that it's faster because it performs incremental compiling. But I'm still a bit unsure about this since I can't find any authoritative documentation about both - eclispse's and sun's - compilers "incremental feature". Is it true that Sun's compiler always compiles every source file and Eclipse's compiler compile only changed files and those that are affected by such a change?
Hi,
This is simple question only...
i did a program in java that accepts input via command line arguments.
I get input of two numbers and operator in command line.
multiplying two numbers, i have to give input as 5 3 *.
But if i give like this, i cant get answer.
Y its not accept * in cmd....
waiting for reply guys...
I am making a text editor using Java swing. I am using JTextArea for the same. I want to know how I can use Undo and Redo functionality in JTextArea as I am not able to use it.
I have a set of data in one JSON structure:
[[task1, 10, 99],
[task2, 10, 99],
[task3, 10, 99],
[task1, 11, 99],
[task2, 11, 99],
[task3, 11, 99]]
and need to convert it to another JSON structure:
[{
label: "task1",
data: [[10, 99], [11, 99]]
},
{
label: "task2",
data: [[10, 99], [11, 99]]
},
{
label: "task3",
data: [[10, 99], [11, 99]]
}]
What's the best way to do this with javascript/java?
In the project I am working I have deployed a SOAP server using Deployment Descriptors (WSDD) files. To do that a webserver (e.g tomcat, jetty) is started and then the following command is executed:
java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient deploy.wsdd
What I need is to skip the above command to avoid a call to the Axis AdminClient. Is it possible to deploy my webservice as war file?
Note: A solution with JWS can't be used due to its limitations.
i'm using enums to replace String constants in my java app (jre 1.5).
is there a performance hit when i treat the enum as a static array of names, in a method that is called constatnly (e.g. when rendering the UI)?
my code looks a bit like this:
public String getValue(int col) {
return ColumnValues.values()[col].toString();
}
thanks, asaf :-)
Hi all,
I have been using JBoss Seam now for over a year and still haven't seen much acceptance here in the US. My metrics are, the number of jobs that indicate JBoss Seam and number of people talking about JBoss Seam (Java groups / JBoss Seam groups, etc.).
Is JBoss Seam more popular outside the US?
Walter
I have written a program that creates nodes that in this class are parts of polynomials and then the two polynomials get added together to become one polynomial (list of nodes). All my code compiles so the only problem I am having is that the nodes are not inserting into the polynomial via the insert method I have in polynomial.java and when running the program it does create nodes and displays them in the 2x^2 format but when it comes to add the polynomials together it displays o as the polynomials, so if anyone can figure out whats wrong and what I can do to fix it it would be much appreciated.
Here is the code:
import java.util.Scanner;
class Polynomial{
public termNode head;
public Polynomial()
{
head = null;
}
public boolean isEmpty()
{
return (head == null);
}
public void display()
{
if (head == null)
System.out.print("0");
else
for(termNode cur = head; cur != null; cur = cur.getNext())
{
System.out.println(cur);
}
}
public void insert(termNode newNode)
{
termNode prev = null;
termNode cur = head;
while (cur!=null && (newNode.compareTo(cur)<0))
{
prev = null;
cur = cur.getNext();
}
if (prev == null)
{
newNode.setNext(head);
head = newNode;
}
else
{
newNode.setNext(cur);
prev.setNext(newNode);
}
}
public void readPolynomial(Scanner kb)
{
boolean done = false;
double coefficient;
int exponent;
termNode term;
head = null; //UNLINK ANY PREVIOUS POLYNOMIAL
System.out.println("Enter 0 and 0 to end.");
System.out.print("coefficient: ");
coefficient = kb.nextDouble();
System.out.println(coefficient);
System.out.print("exponent: ");
exponent = kb.nextInt();
System.out.println(exponent);
done = (coefficient == 0 && exponent == 0);
while(!done)
{
Polynomial poly = new Polynomial();
term = new termNode(coefficient,exponent);
System.out.println(term);
poly.insert(term);
System.out.println("Enter 0 and 0 to end.");
System.out.print("coefficient: ");
coefficient = kb.nextDouble();
System.out.println(coefficient);
System.out.print("exponent: ");
exponent = kb.nextInt();
System.out.println(exponent);
done = (coefficient==0 && exponent==0);
}
}
public static Polynomial add(Polynomial p, Polynomial q)
{
Polynomial r = new Polynomial();
double coefficient;
int exponent;
termNode first = p.head;
termNode second = q.head;
termNode sum = r.head;
termNode term;
while (first != null && second != null)
{
if (first.getExp() == second.getExp())
{
if (first.getCoeff() != 0 && second.getCoeff() != 0);
{
double addCoeff = first.getCoeff() + second.getCoeff();
term = new termNode(addCoeff,first.getExp());
sum.setNext(term);
first.getNext();
second.getNext();
}
}
else if (first.getExp() < second.getExp())
{
sum.setNext(second);
term = new termNode(second.getCoeff(),second.getExp());
sum.setNext(term);
second.getNext();
}
else
{
sum.setNext(first);
term = new termNode(first.getNext());
sum.setNext(term);
first.getNext();
}
}
while (first != null)
{
sum.setNext(first);
}
while (second != null)
{
sum.setNext(second);
}
return r;
}
}
Here is my Node class:
class termNode implements Comparable
{
private int exp;
private double coeff;
private termNode next;
public termNode(double coefficient, int exponent)
{
coeff = coefficient;
exp = exponent;
next = null;
}
public termNode(termNode inTermNode)
{
coeff = inTermNode.coeff;
exp = inTermNode.exp;
}
public void setData(double coefficient, int exponent)
{
coefficient = coeff;
exponent = exp;
}
public double getCoeff()
{
return coeff;
}
public int getExp()
{
return exp;
}
public void setNext(termNode link)
{
next = link;
}
public termNode getNext()
{
return next;
}
public String toString()
{
if (exp == 0)
{
return(coeff + " ");
}
else if (exp == 1)
{
return(coeff + "x");
}
else
{
return(coeff + "x^" + exp);
}
}
public int compareTo(Object other)
{
if(exp ==((termNode) other).exp)
return 0;
else if(exp < ((termNode) other).exp)
return -1;
else
return 1;
}
}
And here is my Test class to run the program.
import java.util.Scanner;
class PolyTest{
public static void main(String [] args)
{
Scanner kb = new Scanner(System.in);
Polynomial r;
Polynomial p = new Polynomial();
System.out.println("Enter first polynomial.");
p.readPolynomial(kb);
Polynomial q = new Polynomial();
System.out.println();
System.out.println("Enter second polynomial.");
q.readPolynomial(kb);
r = Polynomial.add(p,q);
System.out.println();
System.out.print("The sum of ");
p.display();
System.out.print(" and ");
q.display();
System.out.print(" is ");
r.display();
}
}
I am working on a java Ant+Ivy based project that has the following directory structure:
projectRoot/src
projectRoot/classes
projectRoot/conf
projectRoot/webservices
this works perfectly well in Ant but I am looking to migrate to Gradle.
Is there a way to define a non-maven directory structure in gradle or should I be looking to mavenize?