I am trying to download a file from Sharepoint 2007 sp2 document library using GetItem method of the Copy webservice. I am facing the following issues :
In the local instance ( Windows Vista ) I can save only 10.5 Kb of any file. The webservice is returning only 10.5 Kb of data for any file.
On the production server, I am able to List the documents using some credentials but when I am trying to download a document using the same credentials I get a 401 : Unauthorized message. I can download the document using the Sharepoint website successfully.
Trying to tail / parse some log files. Entries start with a date then can span many lines.
This works, but does not ever see new entries to file.
File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");
while (true) {
while(src.hasNext()){
System.out.println("[ " + src.next() + " ]");
}
}
Doesn't seem like Scanner's next() or hasNext() detects new entries to file.
Any idea how else I can implement, basically, a tail -f with custom delimiter.
ok - using Kelly's advise i'm checking & refreshing the scanner, this works. Thank you !!
if anyone has improvement suggestions plz do!
File inputFile = new File("C:/test.txt");
InputStream is = new FileInputStream(inputFile);
InputStream bis = new BufferedInputStream(is);
//bis.skip(inputFile.length());
Scanner src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");
while (true) {
while(src.hasNext()){
System.out.println("[ " + src.next() + " ]");
}
Thread.sleep(50);
if(bis.available() > 0){
src = new Scanner(bis);
src.useDelimiter("\n2010-05-01 ");
}
}
Hi,
I have a list in which I'd like to keep several head pointers. I've tried to create multiple ListIterators on the same list but this forbid me to add new elements in my list... (see Concurrent Modification exception).
I could create my own class but I'd rather use a built-in implementation ;)
To be more specific, here is an inefficient implementation of two basic operations and the one wich doesn't work :
class MyList <E {
private int[] _heads;
private List<E _l;
public MyList ( int nbHeads ) {
_heads = new int[nbHeads];
_l = new LinkedList<E();
}
public void add ( E e ) {
_l.add(e);
}
public E next ( int head ) {
return _l.get(_heads[head++]); // ugly
}
}
class MyList <E {
private Vector<ListIterator<E _iters;
private List<E _l;
public MyList ( int nbHeads ) {
_iters = new Vector<ListIterator<E(nbHeads);
_l = new LinkedList<E();
for( ListIterator<E iter : _iters ) iter = _l.listIterator();
}
public void add ( E e ) {
_l.add(e);
}
public E next ( int head ) {
// ConcurrentModificationException because of the add()
return _iters.get(head).next();
}
}
Emile
Hi,
I'm using Apache XML-RPC 3.1.2 to talk to an online-service. They have something special, they need a hash over the whole XML with a secret key for some kind of security, like this:
String hash = md5(xmlRequest + secretKey);
String requestURL = "http://foo.bar/?authHash=" + hash;
So I need the XML-request like this:
<?xml version="1.0"?>
<methodCall>
<methodName>foo.bar</methodName>
<params>
<param>
<value><struct>
<member><name>bla</name>
<value><int>1</int></value>
</member>
<member><name>blubb</name>
<value><int>2</int></value>
</member>
</struct></value>
</param>
</params>
</methodCall>
But how do I get this String-representation of the XMLRPC-Request with the lib Apache XML-RPC?
Hey,
I have something like the following
TestObjectCreator{
private static Person person;
private static Company company;
static {
person = new Person()
person.setName("Joe");
company = new Company();
company.setName("Apple");
}
public Person createTestPerson(){
return person;
}
public Person createTestCompany(){
return company;
}
}
By applying static{} what am I gaining? I assume the objects are singletons as a result. However, if I did the following:
Person person = TestObjectCreator.createTestPerson();
person.setName("Jill");
Person person2 = TestObjectCreator.createTestPerson();
would person2 be named Jill or Joe?
I'm using the .startsWith() filter in a JDOQL query but it's case sensitive.
So startsWith("ab") doesn't return "Abc" result and so on.
Will I need to use a SQL query to avoid this ?
Consider the following code:
while(true) {
someFunction();
Thread.sleep(1000);
}
What I want is that, someFunction() be called once every 10 seconds. But this is not the case. It is being called every second. I tried Thread.wait(1000), but even that doesnt help. I removed of the while part, just kept the body, and at the end wrote :
Thread.start();
But it throwed an exception. Is there any other solution to this?
this compiles
class ex1
{
public int show()
{
try
{ int a=10/10; return 10;}
catch(ArithmeticException e)
{ System.out.println(e); }
finally
{ System.out.println("Finally");}
System.out.println("hello");
return 20;
}
}
on the other hand this doesn't
class ex15
{
public int show()
{
try
{ int a=10/0; return 10;}
catch(ArithmeticException e)
{ System.out.println(e); }
finally
{ System.out.println("Finally"); return 40;}
System.out.println("hello");
return 20;
}
}
why is it so?
Let's assume I have 3 classes A, B and C, each one extending the previous one.
How do I call the code in A.myMethod() from C.myMethod() if B also implements myMethod?
class A
{
public void myMethod()
{
// some stuff for A
}
}
class B extends A
{
public void myMethod()
{
// some stuff for B
//and than calling A stuff
super.myMethod();
}
}
class C extends B
{
public void myMethod()
{
// some stuff for C
// i don't need stuff from b, but i need call stuff from A
// something like: super.super.myMethod(); ?? how to call A.myMethod(); ??
}
}
Hi,
I came across PECS (short for Producer extends and Consumer super) while reading on Generics.
Can someone explain me how to use PECS to resolve confusion between extends and super?
Thanks in advance !
I am aware that you can initialize an array during instantiation as follows:
String[] names = new String[] {"Ryan", "Julie", "Bob"};
Is there a way to do the same thing with an ArrayList? Or must I add the contents individually with array.add()?
Thanks,
Jonathan
When I create complex type hierarchies (several levels, several types per level), I like to use the final keyword on methods implementing some interface declaration. An example:
interface Garble {
int zork();
}
interface Gnarf extends Garble {
/**
* This is the same as calling {@link #zblah(0)}
*/
int zblah();
int zblah(int defaultZblah);
}
And then
abstract class AbstractGarble implements Garble {
@Override
public final int zork() { ... }
}
abstract class AbstractGnarf extends AbstractGarble implements Gnarf {
// Here I absolutely want to fix the default behaviour of zblah
// No Gnarf shouldn't be allowed to set 1 as the default, for instance
@Override
public final int zblah() {
return zblah(0);
}
// This method is not implemented here, but in a subclass
@Override
public abstract int zblah(int defaultZblah);
}
I do this for several reasons:
It helps me develop the type hierarchy. When I add a class to the hierarchy, it is very clear, what methods I have to implement, and what methods I may not override (in case I forgot the details about the hierarchy)
I think overriding concrete stuff is bad according to design principles and patterns, such as the template method pattern. I don't want other developers or my users do it.
So the final keyword works perfectly for me. My question is:
Why is it used so rarely in the wild? Can you show me some examples / reasons where final (in a similar case to mine) would be very bad?
I appreciate that anything that can be done done by a switch statment can be done by an if else statement.
But are there stylistic rules for when one should use the switch rather than if else statment.
I have a TableModel that is populated from a background running thread. I am calling fireTableRowsInserted when data is inserted, which is NOT on the EDT.
My question is, do I need to use invokeLater for the fireTableRowsInserted?
In other words, is the below correct:
public void putData(TableRow row) {
// we are not on the EDT here...
rows.add(row);
fireTableRowsInserted(rows.size()-1, rows.size()-1);
}
I read http://stackoverflow.com/questions/839178/why-is-javas-iterator-not-an-iterable and http://stackoverflow.com/questions/27240/why-arent-enumerations-iterable, but I still don't understand why this:
void foo(Iterator<X> it) {
for (X x : it) {
bar(x);
baz(x);
}
}
was not made possible. In other words, unless I'm missing something, the above could have been nice and valid syntactic sugar for:
void foo(Iterator<X> it) {
for (X x; it.hasNext();) {
x = it.next();
bar(x);
baz(x);
}
}
I'm looking for a simple commons method or operator that allows me to repeat some String n times. I know I could write this using a for loop, but I wish to avoid for loops whenever necessary and a simple direct method should exist somewhere.
String str = "abc";
String repeated = str.repeat(3);
repeated.equals("abcabcabc");
Related to:
repeat string javascript
Create NSString by repeating another string a given number of times
Edited
I try to avoid for loops when they are not completely necessary because:
They add to the number of lines of code even if they are tucked away in another function.
Someone reading my code has to figure out what I am doing in that for loop. Even if it is commented and has meaningful variables names, they still have to make sure it is not doing anything "clever".
Programmers love to put clever things in for loops, even if I write it to "only do what it is intended to do", that does not preclude someone coming along and adding some additional clever "fix".
They are very often easy to get wrong. For loops that involving indexes tend to generate off by one bugs.
For loops often reuse the same variables, increasing the chance of really hard to find scoping bugs.
For loops increase the number of places a bug hunter has to look.
Hello, recently I went through the inheritance concept.
As we all know, in inheritance, superclass objects are created/initialized prior to subclass objects. So if we create an object of subclass, it will contain all the superclass information.
But I got stuck at one point.
Do the superclass and the subclass methods are present on separate call-stack?
If it is so, is there any specific reason for same?
If it is not so, why they don't appear on same call-stack?
E.g.
// Superclass
class A {
void play1( ) {
// ....
}
}
// Subclass
class B extends A {
void play2( ) {
//.....
}
}
Then does the above 2 methods i.e play1( ) and play2( ) appear on separate call stack?
Thanks.
Hi,
I am trying to do a conversion of a String to integer for which I get a NumberFormatException. The reason is pretty obvious. But I need a workaround here. Following is the sample code.
public class NumberFormatTest {
public static void main(String[] args) {
String num = "9.18E+09";
try{
long val = Long.valueOf(num);
}catch(NumberFormatException ne){
//Try to convert the value to 9180000000 here
}
}
}
I need the logic that goes in the comment section, a generic one would be nice. Thanks.
I have following code running perfectly. It filter records based on single parameter.
public List<Orders> GetOrders(String email)
{
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Orders.class);
query.setFilter("Email == pEmail");
query.setOrdering("Id desc");
query.declareParameters("String pEmail");
query.setRange(0,50);
return (List<Orders>) query.execute(email);
}
Now i want to filter on multiple parameters. sdate and edate is Start Date and End Date.
In datastore it is saved as Date (not String).
public List<Orders> GetOrders(String email,String icode,String sdate, String edate)
{
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Orders.class);
query.setFilter("Email == pEmail");
query.setFilter("ItemCode == pItemCode");
query.declareParameters("String pEmail");
query.declareParameters("String pItemCode");
.....//Set filter and declare other 2 parameters
.....//
......
query.setRange(0,50);
query.setOrdering("Id desc");
return (List<Orders>) query.execute(email,icode,sdate,edate);
}
Any clue?
Assign the following 25 scores to a one dimensional int array called "temp"
34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,66
Move the scores to a 2 dimensional int array called "scores" row wise
-- meaning the first 5 scores go into row 0 etc
I am go through a socket program. In that printStackTrace is caught by the catch block.
Actully what it is?
catch(IOException ioe)
{
ioe.printStackTrace();
}
I am unaware of it. For what they are used?
Hi there,
I'd like to have your expert explanations about an architectural question. Imagine a Spring MVC webapp, with validation API (JSR 303). So for a request, I have a controller that handles the request, then passes it to the service layer, which passes to the DAO one.
Here's my question. At which layer should the validation occur, and how ?
My though is that the controller has to handle basic validation (are mandatory fields empty ? Is the field length ok ? etc.). Then the service layer can do some tricker stuff, that involve other objets. The DAO does no validation at all.
BUT, if I want to implement some unit testing (i.e. test layers below service, not the controllers), I'll end up with unexpected behavior because some validations should have been done in the Controller layer. As we don't use it for unit testing, there is a problem.
What is the best way to deal with this ? I know there is no universal answer, but your personal experience is very welcomed.
Thanks a lot.
Regards.
Contrary to Code Contracts in C#, in JML Code Contracts are just text that's used in the form of comments in the header of a method. Wouldn't it be better to have them exposed as Annotations, then? That way even when compiling the information would persist on the .class's metadata, contrary to comments, that get erased.
Am I missing something?
Thanks