This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Daniel Bauer

Ranch Hand
+ Follow
since Apr 15, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Bauer

I'm going to have to think aloud (and repeat back to you what you said) to make sure I've got it.

So if the array only contains Strings at the time it is passed to the method, another thread could still put other objects into it while the method that thinks it is working on a String[] is accessing it

Aha, that's an interesting point. And it doesn't even have to be threaded- what if I had:I guess there's nothing reasonable that colourStrings[0] could then be...

Note that a cast doesn't change the object.

I like that point.

So if I create the array with then I can't cast it to String[] even if there are Strings (currently) inside it. If I instead create it with then I can perform the cast fine. And if then I were to put non-Strings into the array (which the compiler thinks is OK) then I'd get a runtime ArrayStoreException.

I think I get it. But at first glance it seems so similar to casting Objects that I was stumped when it didn't work.

Thanks for all the replies!
13 years ago
Thanks for your replies, that does start to make a little more sense now.
I have noticed that if I get an Object[] from an internal method like this:Then I can indeed cast the returned Object[] into a String[] without problems. So it makes some sense that the arrays returned from the two toArray() methods behave differently if they were created differently.

I'm still a little weirded out by this whole thing though, I just assumed the direct cast would work and the alternative for converting Object[] to String[] (create a new array, make a loop over all elements, cast each element in turn and copy to second array) sounds ugly and expensive.
13 years ago
You should also consider specifying the color of the text, it could be it's writing black on black.
13 years ago
Well that's more or less what my second code example was doing, just that the one-liner has an extra array instantiation.

But if I have a normal Object array then the cast doesn't work:

This just gives a ClassCastException.

And if I get my Object array from the other Collection.toArray() method, the cast to String[] doesn't work either.

So perhaps my question should be: why is it apparently not possible to cast an Object array to String array (even if all the elements in the array are Strings) unless the Object array is obtained from the Collection.toArray(Object[]) method? Does that method have some special way of creating the array?
13 years ago
Well I think we've got a solution: in the Properties object used for the InitialContext creation, we added:

which apparently forces the InitialContext to use a different settings cache from the other requests. Seems to work so far!
13 years ago
My question starts with the toArray() method of the Collection - from this I get an Object[] back. However I know that each of the elements in the Collection is a String object, so I figured the obvious thing to do would be to cast it so:

Which as I quickly discovered doesn't work, giving a runtime ClassCastException.

I know there is an alternative method in the Collection where you specify the type:

but you have to admit that is pretty ugly and my question goes a little deeper than that.

Why *can't* you just cast an Object[] into a String[] if all of the elements in the array are actually Strings? The reverse cast (from String[] to Object[]) works as expected. Let's say there is no Collection involved, you already received an Object[] from somewhere and wanted to pass it on to another method which accepts String[]. Is the only way to do this to create a new array, loop over the elements and copy and cast each one in turn? Sounds a bit mad.

Maybe this is much easier with the generics in 1.5, I haven't looked too deeply at that because this particular project has to be 1.4. So I'm trying to deepen my understanding - I was a little shocked that the simple cast doesn't work the way I expected it to.
13 years ago
have you tried going into the WAS config, selecting the server settings, and looking at the "Ports" section?
9080 is default, but you could change it to 80 if you wanted to.
13 years ago
We're using a web application in WebSphere which is trying to access an Ldap nameserver on another platform. To do this we're building a Properties object to describe the lookup parameters, and then building an InitialContext object using these parameters:

Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
props.put("com.ibm.ws.naming.ldap.masterurl", remoteLdapUrl);
// ... other properties

// do the lookup
Context ctx = new InitialContext(props);
Object object = ctx.lookup(path);

This works.

However, if another attempt is made to do a (completely seperate) JNDI lookup beforehand, like this:
Context otherContext = new InitialContext();
Object otherObject = otherContext.lookup(anything);

Then the parameterized lookup no longer works. We can examine the InitialContext object ctx, and print out its .getEnvironment() table and it has all the right parameters in it, but it no longer works and just gives a NamingException "First component in name xyz not found". In the error message the Context is still the local server, it doesn't even ask the remote server any more. So it's got the remote Ldap Url in the environment but doesn't seem to use it at all, it just looks in its own WebSphere naming server and then gives up.

Is it possible to use different name servers in the same WebSphere process, or does it somehow cache the details and then only ever use that name server from then on?
Is there any way we can persuade WebSphere to use our remote Url, even after it's done a local lookup on its own name server?

Thanks!
13 years ago
Well, I read this (but thanks).

I have a PHP background and there, if I wanted to see what is written to the session, I could view a session file (in folder specified in cfg).
I wondered, if I setup EHCache to overflow data to disk i could view similar file too. If so - when should I look for it?

regards
D.
or with a recursion

public static void splitBytes(byte[] fileBytes, int offset , int fileCounter) throws Exception {

byte[] outputBytes;

if(fileBytes.length - offset < 500 ) {
outputBytes = new byte[fileBytes.length - offset];
System.arraycopy(fileBytes, offset, outputBytes, 0, fileBytes.length - offset);
saveFile(outputBytes , fileCounter++);
return;
}

outputBytes = new byte[500];
System.arraycopy(fileBytes, offset, outputBytes, 0, 500);
saveFile(outputBytes , fileCounter++);
Thread.sleep(3000);
splitBytes(fileBytes,offset+500, fileCounter++);


}
13 years ago
public static void splitBytes(byte[] fileBytes) throws Exception {


int offset = 0;
int fileCounter = 0;

while (offset < fileBytes.length) {
byte[] outputBytes;

if(fileBytes.length - offset < 500 ) {
outputBytes = new byte[fileBytes.length - offset];
System.arraycopy(fileBytes, offset, outputBytes, 0, fileBytes.length - offset);
saveFile(outputBytes , fileCounter++);
break;
}

outputBytes = new byte[500];
System.arraycopy(fileBytes, offset, outputBytes, 0, 500);
offset +=500 ;
saveFile(outputBytes , fileCounter++);
Thread.sleep(3000);

}

}
13 years ago
Hello everyone.
I have one quick and short question. How to check if I setup a EHCache correctly? My application doesn't throw any exceptions etc. but I couldn't see much improvment in performance. And I suppose I made a mistake in cache configuration.

Could you please help me with this?
hi i have a big file.i have loaded this file to byte[].

now i want to split this byte[] to smaller byte[] chunks of byte[500].

how to do this ?
13 years ago
Bonjour,
Vous pouvez publier cette annonce sur
http://www.bricoccasions.com
Le site internet www.bricoccasions.com est un site d'annonces gratuites pour :
Vendre , acheter ou echanger des materiaux, outillages, decoration, jardinage entre particuliers.

A bientot!
Cordialement.
14 years ago
I conclude that this exam is not worth the time. anyone taking this exam now will be wasting time and money. Either wait for a while till sun updates this exam, or choose something else.