Skip to content

Commit 552e05c

Browse files
committed
rename package
1 parent 83f30e0 commit 552e05c

13 files changed

+5921
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* Copyright (c) 2007 Greg Whalin
3+
* All rights reserved.
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the BSD license
7+
*
8+
* This library is distributed in the hope that it will be
9+
* useful, but WITHOUT ANY WARRANTY; without even the implied
10+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11+
* PURPOSE.
12+
*
13+
* You should have received a copy of the BSD License along with this
14+
* library.
15+
*
16+
* @author greg whalin <[email protected]>
17+
* @version 2.0
18+
*/
19+
package com.danga.MemCached;
20+
21+
import java.io.ByteArrayOutputStream;
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.nio.ByteBuffer;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
public final class ByteBufArrayInputStream extends InputStream implements LineInputStream {
29+
private ByteBuffer[] bufs;
30+
private int currentBuf = 0;
31+
32+
public ByteBufArrayInputStream( List<ByteBuffer> bufs ) throws Exception {
33+
this( bufs.toArray( new ByteBuffer[] {} ) );
34+
}
35+
36+
public ByteBufArrayInputStream( ByteBuffer[] bufs ) throws Exception {
37+
if ( bufs == null || bufs.length == 0 )
38+
throw new Exception( "buffer is empty" );
39+
40+
this.bufs = bufs;
41+
for ( ByteBuffer b : bufs )
42+
b.flip();
43+
}
44+
45+
public int read() {
46+
do {
47+
if ( bufs[currentBuf].hasRemaining() )
48+
return bufs[currentBuf].get();
49+
currentBuf++;
50+
}
51+
while ( currentBuf < bufs.length );
52+
53+
currentBuf--;
54+
return -1;
55+
}
56+
57+
public int read( byte[] buf ) {
58+
int len = buf.length;
59+
int bufPos = 0;
60+
do {
61+
if ( bufs[currentBuf].hasRemaining() ) {
62+
int n = Math.min( bufs[currentBuf].remaining(), len-bufPos );
63+
bufs[currentBuf].get( buf, bufPos, n );
64+
bufPos += n;
65+
}
66+
currentBuf++;
67+
}
68+
while ( currentBuf < bufs.length && bufPos < len );
69+
70+
currentBuf--;
71+
72+
if ( bufPos > 0 || ( bufPos == 0 && len == 0 ) )
73+
return bufPos;
74+
else
75+
return -1;
76+
}
77+
78+
public String readLine() throws IOException {
79+
byte[] b = new byte[1];
80+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
81+
boolean eol = false;
82+
83+
while ( read( b, 0, 1 ) != -1 ) {
84+
if ( b[0] == 13 ) {
85+
eol = true;
86+
}
87+
else {
88+
if ( eol ) {
89+
if ( b[0] == 10 )
90+
break;
91+
eol = false;
92+
}
93+
}
94+
95+
// cast byte into char array
96+
bos.write( b, 0, 1 );
97+
}
98+
99+
if ( bos == null || bos.size() <= 0 ) {
100+
throw new IOException( "++++ Stream appears to be dead, so closing it down" );
101+
}
102+
103+
// else return the string
104+
return bos.toString().trim();
105+
}
106+
107+
public void clearEOL() throws IOException {
108+
byte[] b = new byte[1];
109+
boolean eol = false;
110+
while ( read( b, 0, 1 ) != -1 ) {
111+
112+
// only stop when we see
113+
// \r (13) followed by \n (10)
114+
if ( b[0] == 13 ) {
115+
eol = true;
116+
continue;
117+
}
118+
119+
if ( eol ) {
120+
if ( b[0] == 10 )
121+
break;
122+
eol = false;
123+
}
124+
}
125+
}
126+
127+
public String toString() {
128+
StringBuilder sb = new StringBuilder( "ByteBufArrayIS: " );
129+
sb.append( bufs.length ).append( " bufs of sizes: \n" );
130+
131+
for ( int i=0; i < bufs.length; i++ ) {
132+
sb.append( " " )
133+
.append (i ).append( ": " ).append( bufs[i] ).append( "\n" );
134+
}
135+
return sb.toString();
136+
}
137+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* MemCached Java client
3+
* Copyright (c) 2008 Greg Whalin
4+
* All rights reserved.
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the BSD license
8+
*
9+
* This library is distributed in the hope that it will be
10+
* useful, but WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12+
* PURPOSE.
13+
*
14+
* You should have received a copy of the BSD License along with this
15+
* library.
16+
*
17+
* Adds the ability for the MemCached client to be initialized
18+
* with a custom class loader. This will allow for the
19+
* deserialization of classes that are not visible to the system
20+
* class loader.
21+
*
22+
* @author Vin Chawla <[email protected]>
23+
* @version 2.0
24+
*/
25+
package com.danga.MemCached;
26+
27+
import java.util.*;
28+
import java.util.zip.*;
29+
import java.io.*;
30+
31+
public class ContextObjectInputStream extends ObjectInputStream {
32+
33+
ClassLoader mLoader;
34+
35+
public ContextObjectInputStream( InputStream in, ClassLoader loader ) throws IOException, SecurityException {
36+
super( in );
37+
mLoader = loader;
38+
}
39+
40+
protected Class resolveClass( ObjectStreamClass v ) throws IOException, ClassNotFoundException {
41+
if ( mLoader == null )
42+
return super.resolveClass( v );
43+
else
44+
return Class.forName( v.getName(), true, mLoader );
45+
}
46+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* MemCached Java client
3+
* Copyright (c) 2007 Greg Whalin
4+
* All rights reserved.
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the BSD license
8+
*
9+
* This library is distributed in the hope that it will be
10+
* useful, but WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12+
* PURPOSE.
13+
*
14+
* You should have received a copy of the BSD License along with this
15+
* library.
16+
*
17+
* This is an interface implemented by classes that want to receive callbacks
18+
* in the event of an error in {@link MemCachedClient}. The implementor can do
19+
* things like flush caches or perform additioonal logging.
20+
*
21+
* @author Dan Zivkovic <[email protected]>
22+
* @version 2.0
23+
*/
24+
package com.danga.MemCached;
25+
26+
public interface ErrorHandler {
27+
28+
/**
29+
* Called for errors thrown during initialization.
30+
*/
31+
public void handleErrorOnInit( final MemCachedClient client ,
32+
final Throwable error );
33+
34+
/**
35+
* Called for errors thrown during {@link MemCachedClient#get(String)} and related methods.
36+
*/
37+
public void handleErrorOnGet( final MemCachedClient client ,
38+
final Throwable error ,
39+
final String cacheKey );
40+
41+
/**
42+
* Called for errors thrown during {@link MemCachedClient#getMulti(String)} and related methods.
43+
*/
44+
public void handleErrorOnGet( final MemCachedClient client ,
45+
final Throwable error ,
46+
final String[] cacheKeys );
47+
48+
/**
49+
* Called for errors thrown during {@link MemCachedClient#set(String,Object)} and related methods.
50+
*/
51+
public void handleErrorOnSet( final MemCachedClient client ,
52+
final Throwable error ,
53+
final String cacheKey );
54+
55+
/**
56+
* Called for errors thrown during {@link MemCachedClient#delete(String)} and related methods.
57+
*/
58+
public void handleErrorOnDelete( final MemCachedClient client ,
59+
final Throwable error ,
60+
final String cacheKey );
61+
62+
/**
63+
* Called for errors thrown during {@link MemCachedClient#flushAll()} and related methods.
64+
*/
65+
public void handleErrorOnFlush( final MemCachedClient client ,
66+
final Throwable error );
67+
68+
/**
69+
* Called for errors thrown during {@link MemCachedClient#stats()} and related methods.
70+
*/
71+
public void handleErrorOnStats( final MemCachedClient client ,
72+
final Throwable error );
73+
74+
} // interface
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* MemCached Java client
3+
* Copyright (c) 2007 Greg Whalin
4+
* All rights reserved.
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the BSD license
8+
*
9+
* This library is distributed in the hope that it will be
10+
* useful, but WITHOUT ANY WARRANTY; without even the implied
11+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12+
* PURPOSE.
13+
*
14+
* You should have received a copy of the BSD License along with this
15+
* library.
16+
*
17+
* @author greg whalin <[email protected]>
18+
* @version 2.0
19+
*/
20+
package com.danga.MemCached;
21+
22+
import java.io.IOException;
23+
24+
public interface LineInputStream {
25+
26+
/**
27+
* Read everything up to the next end-of-line. Does
28+
* not include the end of line, though it is consumed
29+
* from the input.
30+
* @return All next up to the next end of line.
31+
*/
32+
public String readLine() throws IOException;
33+
34+
/**
35+
* Read everything up to and including the end of line.
36+
*/
37+
public void clearEOL() throws IOException;
38+
39+
/**
40+
* Read some bytes.
41+
* @param buf The buffer into which read.
42+
* @return The number of bytes actually read, or -1 if none could be read.
43+
*/
44+
public int read( byte[] buf ) throws IOException;
45+
}

0 commit comments

Comments
 (0)