< prev index next >
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/hpack/Huffman.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 23,33 ****
* questions.
*/
package jdk.incubator.http.internal.hpack;
import java.io.IOException;
- import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import static java.lang.String.format;
/**
--- 23,32 ----
*** 49,68 ****
{
reset();
}
! public void read(ByteBuffer source, Appendable destination,
! boolean isLast) {
read(source, destination, true, isLast);
}
// Takes 'isLast' rather than returns whether the reading is done or
// not, for more informative exceptions.
! void read(ByteBuffer source, Appendable destination, boolean reportEOS,
! boolean isLast) {
!
Node c = curr;
int l = len;
/*
Since ByteBuffer is itself stateful, its position is
remembered here NOT as a part of Reader's state,
--- 48,69 ----
{
reset();
}
! public void read(ByteBuffer source,
! Appendable destination,
! boolean isLast) throws IOException {
read(source, destination, true, isLast);
}
// Takes 'isLast' rather than returns whether the reading is done or
// not, for more informative exceptions.
! void read(ByteBuffer source,
! Appendable destination,
! boolean reportEOS, /* reportEOS is exposed for tests */
! boolean isLast) throws IOException {
Node c = curr;
int l = len;
/*
Since ByteBuffer is itself stateful, its position is
remembered here NOT as a part of Reader's state,
*** 75,94 ****
for (; p != 0; p >>= 1) {
c = c.getChild(p & d);
l++;
if (c.isLeaf()) {
if (reportEOS && c.isEOSPath) {
! throw new IllegalArgumentException("Encountered EOS");
}
try {
! destination.append(c.getChar());
! } catch (RuntimeException | Error e) {
! source.position(pos);
! throw e;
} catch (IOException e) {
! source.position(pos);
! throw new UncheckedIOException(e);
}
c = INSTANCE.root;
l = 0;
}
curr = c;
--- 76,99 ----
for (; p != 0; p >>= 1) {
c = c.getChild(p & d);
l++;
if (c.isLeaf()) {
if (reportEOS && c.isEOSPath) {
! throw new IOException("Encountered EOS");
}
+ char ch;
try {
! ch = c.getChar();
! } catch (IllegalStateException e) {
! source.position(pos); // do we need this?
! throw new IOException(e);
! }
! try {
! destination.append(ch);
} catch (IOException e) {
! source.position(pos); // do we need this?
! throw e;
}
c = INSTANCE.root;
l = 0;
}
curr = c;
*** 105,119 ****
}
if (c.isEOSPath && len <= 7) {
return; // it's ok, some extra padding bits
}
if (c.isEOSPath) {
! throw new IllegalArgumentException(
"Padding is too long (len=" + len + ") " +
"or unexpected end of data");
}
! throw new IllegalArgumentException(
"Not a EOS prefix padding or unexpected end of data");
}
public void reset() {
curr = INSTANCE.root;
--- 110,124 ----
}
if (c.isEOSPath && len <= 7) {
return; // it's ok, some extra padding bits
}
if (c.isEOSPath) {
! throw new IOException(
"Padding is too long (len=" + len + ") " +
"or unexpected end of data");
}
! throw new IOException(
"Not a EOS prefix padding or unexpected end of data");
}
public void reset() {
curr = INSTANCE.root;
*** 507,518 ****
* @return number of bytes
*
* @throws NullPointerException
* if the value is null
* @throws IndexOutOfBoundsException
! * if any invocation of {@code value.charAt(i)}, where {@code start
! * <= i < end} would throw an IndexOutOfBoundsException
*/
public int lengthOf(CharSequence value, int start, int end) {
int len = 0;
for (int i = start; i < end; i++) {
char c = value.charAt(i);
--- 512,523 ----
* @return number of bytes
*
* @throws NullPointerException
* if the value is null
* @throws IndexOutOfBoundsException
! * if any invocation of {@code value.charAt(i)}, where
! * {@code start <= i < end} would throw an IndexOutOfBoundsException
*/
public int lengthOf(CharSequence value, int start, int end) {
int len = 0;
for (int i = start; i < end; i++) {
char c = value.charAt(i);
< prev index next >