cache: fix writeBigSmart
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.cache.io;
|
package net.runelite.cache.io;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
@@ -98,11 +99,11 @@ public final class OutputStream extends java.io.OutputStream
|
|||||||
|
|
||||||
public void writeBigSmart(int value)
|
public void writeBigSmart(int value)
|
||||||
{
|
{
|
||||||
|
Preconditions.checkArgument(value >= 0);
|
||||||
if (value >= 65536)
|
if (value >= 65536)
|
||||||
{
|
{
|
||||||
ensureRemaining(5);
|
ensureRemaining(4);
|
||||||
this.writeByte(-1);
|
this.writeInt((1 << 31) | value);
|
||||||
this.writeInt(Integer.MAX_VALUE & value);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
44
cache/src/test/java/net/runelite/cache/io/OutputStreamTest.java
vendored
Normal file
44
cache/src/test/java/net/runelite/cache/io/OutputStreamTest.java
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.cache.io;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class OutputStreamTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testWriteBigSmart()
|
||||||
|
{
|
||||||
|
OutputStream os = new OutputStream();
|
||||||
|
os.writeBigSmart(42);
|
||||||
|
os.writeBigSmart(70000);
|
||||||
|
|
||||||
|
InputStream is = new InputStream(os.getArray());
|
||||||
|
Assert.assertEquals(42, is.readBigSmart());
|
||||||
|
Assert.assertEquals(70000, is.readBigSmart());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user