If given subnet address e.g. 192.168.10.0/24
How to determine mask length ? (/24)
How to determine mask address ? (255.255.255.0)
How to determine network address ? (192.168.10.0)
Here's what I am looking to accomplish, I have a class that has an enum of some values and I want to subclass that and add more values to the enum. This is a bad example, but:
public class Digits
{
public enum Digit
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}
}
public class HexDigits extends Digits
{
public enum Digit
{
A, B, C, D, E, F
}
}
so that HexDigits.Digit contains all Hex Digits. Is that possible?
I want to create a JSON object. I have tried the following
myString=new JSONObject().put("JSON", sampleClass).toString();
but mystring gives me {"SampleClass@170f98"}.
I also tried the following
XStream xsStream=new XStream(new JsonHierarchicalStreamDriver());
SampleClass sampleClass=new SampleClass(userset.getId(),userset.getUsername());
myString=xsStream.toXML(sampleClass);
It works but when i use getJSON in javascript to get myString it does not work.
I am writing a simple multithreaded socketserver and I am wondering how best to handle incoming connections:
create a new thread for each new connection. The number of concurrent threads would be limited and waiting connections limited by specifying a backlog
add all incoming connections into a queue and have a pool of worker threads that process the queue
I am inclined to go for option 2 because I really don't want to refuse any connections, even under high loads, but I am wondering if there are any considerations I should be aware of with accepting effectively unlimited connections?
Suppose I have a string that contains '¿'. How would I find all those unicode characters? Should I test for their code? How would I do that?
I want to detect it to avoid sax parser exception which I am getting it while parsing the xml
saved as a clob in oracle 10g database.
Exception
javax.servlet.ServletException: org.xml.sax.SAXParseException: Invalid byte 1 of 1-byte UTF-8 sequence.
I know there are LOT of questions like that but I can't find one specific to my situation. I have 4x4 matrices implemented as NIO float buffers (These matrices are used for OpenGL). Now I want to implement a multiply method which multiplies Matrix A with Matrix B and stores the result in Matrix C. So the code may look like this:
class Matrix4f
{
private FloatBuffer buffer = FloatBuffer.allocate(16);
public Matrix4f multiply(Matrix4f matrix2, Matrix4f result)
{
{{{result = this * matrix2}}} <-- I need this code
return result;
}
}
What is the fastest possible code to do this multiplication? Some OpenGL implementations (Like the OpenGL ES stuff in Android) provide native code for this but others doesn't. So I want to provide a generic multiplication method for these implementations.
Say I have two threads and an object. One thread assigns the object:
public void assign(MyObject o) {
myObject = o;
}
Another thread uses the object:
public void use() {
myObject.use();
}
Does the variable myObject have to be declared as volatile? I am trying to understand when to use volatile and when not, and this is puzzling me. Is it possible that the second thread keeps a reference to an old object in its local memory cache? If not, why not?
Thanks a lot.
i have installed open cms on my local machine and it perfectly works fine.
But in order to work it corre,ty it is mentioned that i have to modify the my.ini file and set max_alllowed_packed site to 32
I have done it and it works perfectly fine
but can i modify this file if i use a third party hosting provider for tomcat and mysql??
This is what I want to do:
Input: ArrayList that contains a bunch of .jpg URLs
Download the image (using HttpURLConnection maybe?)
Resize
Save as xxx.jpg, locally
I don't know where to start. I'd appreciate if anyone can tell me what to study to do the steps 1~3.
Lets say that I have the following code:
public class Shelter<A extends Animal, B extends Animal>
{
List<A> topFloor = new Vector<A>();
List<B> bottomFloor = new Vector<B>();
public A getFirstTopFloorAnimal(){return topFloor.firstElement();}
public B getFirstBottomFloorAnimal(){return bottomFloor.firstElement();}
//This compiles but when I try to use it, it only returns objects
public List<Animal> getAnimals()
{
Vector a = new Vector(topFloor);
a.addAll(bottomFloor);
return a;
}
}
Now for somereason the following code compiles. But when I try to use getAnimals() I get a of objects instead of Animal. Any ideas why this is? Does this have to do with the List is NOT a List idea in the Generics tutorial?
Thank you.
I can understand why network apps would use multiplexing (to not create too many threads), and why programs would use async calls for pipelining (more efficient). But I don't understand the purpose of AsynchronousFileChannel.
Any ideas?
I'm trying to make a program that uploads a image to a webserver that accepts multipart file-uploads.
More specificly i want to make a http POST request to http://iqs.me that sends a file in the variable "pic".
I've made a lot of tries but i don't know if i've even been close. The hardest part seems to be to get a HttpURLConnection to make a request of the type POST. The response i get looks like it makes a GET.
(And i want to do this without any third party libs)
UPDATE: non-working code goes here (no errors but doesn't seem to do a POST):
HttpURLConnection conn = null;
BufferedReader br = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
InputStream is = null;
OutputStream os = null;
boolean ret = false;
String StrMessage = "";
String exsistingFileName = "myScreenShot.png";
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;
String responseFromServer = "";
String urlString = "http://iqs.local.com/index.php";
try{
FileInputStream fileInputStream = new FileInputStream( new File(exsistingFileName) );
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
dos = new DataOutputStream( conn.getOutputStream() );
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"pic\";" + " filename=\"" + exsistingFileName +"\"" + lineEnd);
dos.writeBytes(lineEnd);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0){
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
fileInputStream.close();
dos.flush();
dos.close();
}catch (MalformedURLException ex){
System.out.println("Error:"+ex);
}catch (IOException ioe){
System.out.println("Error:"+ioe);
}
try{
inStream = new DataInputStream ( conn.getInputStream() );
String str;
while (( str = inStream.readLine()) != null){
System.out.println(str);
}
inStream.close();
}catch (IOException ioex){
System.out.println("Error: "+ioex);
}
I am maintaining this servlet that has a HttpServletResponse response that replies back to the client an XML message. I want to take the XML message and convert it to JSON, then send the JSON back.
I want to avoid writing my own JSON converter if possible. Does anyone have a good method of doing this?
I googled for this: http://pvoss.wordpress.com/2009/02/26/servlet-filter-to-convert-xml-to-json/ , which is exactly what I want but they are using a hacked dom4j jar which doesn't help me.
class A extends ApiClass
{
public void duplicateMethod()
{
}
}
class B extends AnotherApiClass
{
public void duplicateMethod()
{
}
}
I have two classes which extend different api classes. The two class has some duplicate
methods(same method repeated in both class) and how to remove this duplication?
Edit
The ApiClass is not under my control
Hi, I'd like to know if it is possible to make a progress bar displayed on the taskbar like Windows Explorer does when there's a file operation going on? I saw many examples, but they all involved C#.
SWT won't cut it.
Suppose I have a big program that consists of hundreds of methods in it. And according to the nature of input the program flow is getting changed.
Think I want to make a change to the original flow. And it is big hassle to find call hierarchy/ references and understand the flow.
Do I have any solution for this within Eclipse? Or a plugin? As an example, I just need a Log of method names that is in order of time. Then I don't need to worry about the methods that are not relevant with my "given input"
Update : Using debug mode in eclipse or adding print messages are not feasible. The program is sooooo big. :)
I have a large distributed program across many different physical servers, each program spawns many threads, each thread use Math.random() in its operations to draw a piece from many common resource pools.
The goal is to utilize the pools evenly across all operations. Sometimes, it doesn't appear so random by looking at a snapshot on a resource pool to see which pieces it's getting at that instant (it might actually be, but it's hard to measure and find out for sure).
Is there something that's better than Math.random() and performs just as good (not much worse at least)?
What complexity are the methods multiply, divide and pow in BigInteger currently? There is no mention of the computational complexity in the documentation (nor anywhere else).
Hi guys,
if I have the following private member:
private int xIndex;
How should I name my gettter/setter:
getXindex()
setXindex(int value)
or
getxIndex()
setxIndex(int value)
How should I go about implementing a method that gets a String composed of Latin characters to translate it into a String composed of a different set of characters, let's say Cyrillic.
Hello!
In one of my Struts action I've got the following code in a method:
...
List<Object> retrievedListOfObjects = c.getListOfObjects();
return mapping.findForward("fw_view");
}
fw_view leads to a new Struts action with another Struts form. Let's say this form has got among others the following field
List<Object> listOfObjects;
I now want to pass the retrievedListOfObjects from within the first Struts action to the form of the following Struts action.
Is this possible without storing it in the session?
Dear All:
Was wondering, which is correct:
Option One
class A {
public void methodOne() {
synchronized(this) {
modifyvalue
notifyAll()
}
}
public void methodTwo() {
while (valuenotmodified) {
synchronized(this) {
wait()
}
}
}
Option Two
class A {
public void methodOne() {
modifyvalue
synchronized(this) {
notifyAll()
}
}
public void methodTwo() {
while (valuenotmodified) {
synchronized(this) {
wait()
}
}
}
and why?
Thank you
Misha