Skip to content
Snippets Groups Projects
Commit 72e42815 authored by brinn's avatar brinn
Browse files

add: implement missing methods readUTF() and writeUTF()

fix: method readUnsignedShort()

SVN: 19746
parent 86375d37
No related branches found
No related tags found
No related merge requests found
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
package ch.systemsx.cisd.common.filesystem; package ch.systemsx.cisd.common.filesystem;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked; import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked;
/** /**
...@@ -162,8 +164,7 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile ...@@ -162,8 +164,7 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile
public int readUnsignedByte() throws IOExceptionUnchecked public int readUnsignedByte() throws IOExceptionUnchecked
{ {
final byte b = buf.get(); return buf.get() & 0xff;
return (b < 0) ? 256 + b : b;
} }
public short readShort() throws IOExceptionUnchecked public short readShort() throws IOExceptionUnchecked
...@@ -173,8 +174,7 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile ...@@ -173,8 +174,7 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile
public int readUnsignedShort() throws IOExceptionUnchecked public int readUnsignedShort() throws IOExceptionUnchecked
{ {
final short s = buf.get(); return buf.getShort() & 0xffff;
return (s < 0) ? 65536 + s : s;
} }
public char readChar() throws IOExceptionUnchecked public char readChar() throws IOExceptionUnchecked
...@@ -210,12 +210,17 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile ...@@ -210,12 +210,17 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/** public String readUTF()
* @throws UnsupportedOperationException
*/
public String readUTF() throws UnsupportedOperationException
{ {
throw new UnsupportedOperationException(); try
{
final byte[] strBuf = new byte[readUnsignedShort()];
buf.get(strBuf);
return new String(strBuf, "UTF-8");
} catch (UnsupportedEncodingException ex)
{
throw CheckedExceptionTunnel.wrapIfNecessary(ex);
}
} }
public void write(int b) throws IOExceptionUnchecked public void write(int b) throws IOExceptionUnchecked
...@@ -293,12 +298,17 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile ...@@ -293,12 +298,17 @@ public class ByteBufferRandomAccessFile implements IRandomAccessFile
} }
} }
/**
* @throws UnsupportedOperationException
*/
public void writeUTF(String str) throws UnsupportedOperationException public void writeUTF(String str) throws UnsupportedOperationException
{ {
throw new UnsupportedOperationException(); try
{
final byte[] strBuf = str.getBytes("UTF-8");
writeShort(strBuf.length);
write(strBuf);
} catch (UnsupportedEncodingException ex)
{
throw CheckedExceptionTunnel.wrapIfNecessary(ex);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment