Skip to content
Commits on Source (14)
### How to update
# This is copied from OpenHFT/.gitignore
# update the original and run OpenHFT/update_gitignore.sh
### Compiled class file
*.class
# Package Files #
### Package Files
*.jar
*.war
*.ear
# IntelliJ
### Log file
*.log
### IntelliJ
*.iml
*.ipr
*.iws
.idea
.attach_pid*
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
### Virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Eclipse
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
### Eclipse template
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.project
.settings/
.loadpath
# maven
target
# tests
*.bin
*.deleteme
.attach_pid*
### Queue files
*.cq4t
*.cq4
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
\ No newline at end of file
== Copyright 2016 higherfrequencytrading.com
Licensed under the *Apache License, Version 2.0* (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
This diff is collapsed.
# Chronicle Bytes
Chronicle Bytes contains all the low level memory access wrappers. It is built on Chronicle Core's direct memory and OS system call access.
Chronicle Bytes has a similar purpose to Java NIO's ByteBuffer with some extensions.
The API supports.
- 64-bit sizes
- UTF-8 and ISO-8859-1 encoded strings.
- thread safe off heap memory operations.
- deterministic release of resources via reference counting.
- compressed data types such as stop bit encoding.
- elastic ByteBuffer wrappers which resize as required.
- parsing text and writing text directly to off heap bytes.
# Comparison of access to native memory
| Access | ByteBuffer | Netty IOBuffer | Aeron UnsafeBuffer | Chronicle Bytes |
|--------------------------------------------|:---------------:|:---------------:|:--------------------:|:--------------------:|
| Read/write primitives in native memory | yes | yes | yes | yes |
| Separate Mutable interfaces | run time check | run time check | yes | yes |
| Read/Write UTF8 strings | no | no | String | any CharSequence + Appendable |
| Read/Write ISO-8859-1 strings | no | no | ? | any CharSequence + Appendable |
| Support Endianness | Big and Little | Big and Little | Big and Little | Native only |
| Size of buffer | 31-bit | 31-bit | 31-bit | 63-bit |
| Elastic ByteBuffers | no | yes | no | yes |
| Disable bounds checks | no | no | set globally | by buffer |
| Wrap an address | no | no | yes | yes |
| Thread safe read/write, CAS and atomic add operations | no |no | int, long | int, long, float and double |
| Streaming access | yes |yes | no | yes |
| Deterministic release of memory | Internal API | Internal API | Caller's responsibility | yes |
| Separate read and write position | no | yes | na | yes |
openhft-chronicle-bytes (2.17.17-1) unstable; urgency=medium
* Team upload.
* New upstream version 2.17.17.
* Remove build dependency on libsnappy-java.
* Bump libopenhft-chronicle-core-java build dependency to 2.17.5.
-- Andrej Shadura <andrewsh@debian.org> Wed, 27 Feb 2019 19:00:32 +0100
openhft-chronicle-bytes (1.16.25-1) experimental; urgency=medium
* Team upload to experimental.
* New upstream release 1.6.25.
* Version dependency on openhft-chronicle-core
* Bump Standards-Version to 4.2.1
* Update Vcs URLs to point to Salsa
-- tony mancill <tmancill@debian.org> Thu, 13 Sep 2018 22:20:52 -0700
openhft-chronicle-bytes (1.1.15-1) unstable; urgency=medium
* Initial release (Closes: #832915)
......
......@@ -10,13 +10,12 @@ Build-Depends:
libintellij-annotations-java,
libmaven-bundle-plugin-java,
libmockito-java,
libopenhft-chronicle-core-java,
libopenhft-chronicle-core-java (>= 2.17.5),
libslf4j-java,
libsnappy-java,
maven-debian-helper (>= 2.1)
Standards-Version: 3.9.8
Vcs-Git: https://anonscm.debian.org/git/pkg-java/openhft-chronicle-bytes.git
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/openhft-chronicle-bytes.git
Standards-Version: 4.2.1
Vcs-Git: https://salsa.debian.org/java-team/openhft-chronicle-bytes.git
Vcs-Browser: https://salsa.debian.org/java-team/openhft-chronicle-bytes
Homepage: https://github.com/OpenHFT/Chronicle-Bytes
Package: libopenhft-chronicle-bytes-java
......
......@@ -4,13 +4,14 @@ Source: https://github.com/OpenHFT/Chronicle-Bytes
Files-Excluded: *.iml
Files: *
Copyright: 2014-2015, Higher Frequency Trading
Copyright: 2014-2018, Higher Frequency Trading
License: LGPL-3
On Debian systems, the full text of the LGPL-3 license
can be found in the file '/usr/share/common-licenses/LGPL-3'
Files: debian/*
Copyright: 2016, Emmanuel Bourg <ebourg@apache.org>
2018, tony mancill <tmancill@debian.org>
License: Apache-2.0
On Debian systems, the full text of the Apache-2.0 license
can be found in the file '/usr/share/common-licenses/Apache-2.0'
......@@ -2,4 +2,5 @@
net.openhft chronicle-bom * * * *
net.openhft third-party-bom * * * *
org.apache.maven.plugins maven-scm-publish-plugin * * * *
org.apache.maven.plugins maven-javadoc-plugin * * * *
org.apache.servicemix.tooling depends-maven-plugin * * * *
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2015 higherfrequencytrading.com
~ Copyright 2016 chronicle.software
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Lesser General Public License as published by
~ the Free Software Foundation, either version 3 of the License.
~ Licensed under the *Apache License, Version 2.0* (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Lesser General Public License for more details.
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses />.
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License..
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
......@@ -20,34 +20,39 @@
<parent>
<groupId>net.openhft</groupId>
<artifactId>java-parent-pom</artifactId>
<version>1.1.10</version>
<version>1.1.17</version>
<relativePath />
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>chronicle-bytes</artifactId>
<version>1.1.15</version>
<version>2.17.17</version>
<name>OpenHFT/Chronicle-Bytes</name>
<description>Chronicle-Bytes</description>
<packaging>bundle</packaging>
<properties>
<compiler.argument>-Xlint:deprecation</compiler.argument>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>third-party-bom</artifactId>
<artifactId>third-party-bom
</artifactId> <!-- PLEASE DON'T LEAVE THIS ON A SNAPSHOT because they get missed in a release -->
<type>pom</type>
<version>3.4.20</version>
<version>3.6.9</version>
<scope>import</scope>
</dependency>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId>
<version>1.10.30</version>
<version>2.17.153</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -68,12 +73,6 @@
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
......@@ -89,7 +88,29 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<runOrder>random</runOrder>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-publish-plugin</artifactId>
......@@ -143,12 +164,17 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}
</Bundle-SymbolicName>
<Bundle-Name>OpenHFT :: ${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>
net.openhft.chronicle.bytes
net.openhft.chronicle.bytes.*;-noimport:=true
</Export-Package>
<Import-Package>
org.xerial.snappy;resolution:=optional,
*
</Import-Package>
</instructions>
</configuration>
<executions>
......@@ -167,12 +193,44 @@
</plugins>
</build>
<profiles>
<profile>
<id>java9</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
<compilerArgs>
<arg>--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED</arg>
<arg>--add-exports=java.base/sun.nio.ch=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-exports java.base/jdk.internal.ref=ALL-UNNAMED --add-exports
java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.base/sun.nio.ch=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<scm>
<url>scm:git:git@github.com:OpenHFT/Chronicle-Bytes.git</url>
<connection>scm:git:git@github.com:OpenHFT/Chronicle-Bytes.git</connection>
<developerConnection>scm:git:git@github.com:OpenHFT/Chronicle-Bytes.git
</developerConnection>
<tag>chronicle-bytes-1.1.15</tag>
<tag>chronicle-bytes-2.17.17</tag>
</scm>
</project>
This diff is collapsed.
/*
* Copyright 2016 higherfrequencytrading.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package net.openhft.chronicle.bytes;
import net.openhft.chronicle.bytes.algo.BytesStoreHash;
import java.nio.BufferUnderflowException;
/*
* Created by Peter Lawrey on 07/05/16.
*/
public abstract class AbstractBytesStore<B extends BytesStore<B, Underlying>, Underlying>
implements BytesStore<B, Underlying> {
@Override
public int peekUnsignedByte(long offset) throws BufferUnderflowException {
return offset >= readLimit() ? -1 : readUnsignedByte(offset);
}
@Override
public int hashCode() {
return BytesStoreHash.hash32(this);
}
@Override
public long readPosition() {
return 0L;
}
@Override
public long readRemaining() {
return this.capacity();
}
@Override
public long start() {
return 0L;
}
}
/*
* Copyright (C) 2015 higherfrequencytrading.com
* Copyright 2016 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* http://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.bytes;
import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.annotation.ForceInline;
import net.openhft.chronicle.core.annotation.Java9;
import net.openhft.chronicle.core.annotation.NotNull;
import net.openhft.chronicle.core.io.IORuntimeException;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.UTFDataFormatException;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
/**
* Created by peter on 30/08/15.
/*
* Created by Peter Lawrey on 30/08/15.
*/
public class AppendableUtil {
@SuppressWarnings("rawtypes")
public enum AppendableUtil {
;
public static void setCharAt(@NotNull Appendable sb, int index, char ch)
throws IllegalArgumentException, BufferOverflowException, IORuntimeException {
throws IllegalArgumentException, BufferOverflowException {
if (sb instanceof StringBuilder)
((StringBuilder) sb).setCharAt(index, ch);
else if (sb instanceof Bytes)
......@@ -40,19 +44,23 @@ public class AppendableUtil {
throw new IllegalArgumentException("" + sb.getClass());
}
public static void parseUtf8(@org.jetbrains.annotations.NotNull BytesStore bs, StringBuilder sb, int utflen) throws UTFDataFormatRuntimeException {
BytesInternal.parseUtf8(bs, bs.readPosition(), sb, utflen);
}
@ForceInline
public static void setLength(@NotNull Appendable sb, int newLength)
throws BufferUnderflowException, IllegalArgumentException {
if (sb instanceof StringBuilder)
((StringBuilder) sb).setLength(newLength);
else if (sb instanceof Bytes)
((Bytes) sb).readPosition(newLength);
((Bytes) sb).readPositionRemaining(0, newLength);
else
throw new IllegalArgumentException("" + sb.getClass());
}
public static void append(@NotNull Appendable sb, double value)
throws IllegalArgumentException, IORuntimeException, BufferOverflowException {
throws IllegalArgumentException, BufferOverflowException {
if (sb instanceof StringBuilder)
((StringBuilder) sb).append(value);
else if (sb instanceof Bytes)
......@@ -62,7 +70,7 @@ public class AppendableUtil {
}
public static void append(@NotNull Appendable sb, long value)
throws IllegalArgumentException, IORuntimeException, BufferOverflowException {
throws IllegalArgumentException, BufferOverflowException {
if (sb instanceof StringBuilder)
((StringBuilder) sb).append(value);
else if (sb instanceof Bytes)
......@@ -71,7 +79,7 @@ public class AppendableUtil {
throw new IllegalArgumentException("" + sb.getClass());
}
public static <ACS extends Appendable & CharSequence> void append(@NotNull ACS sb, String str) {
public static <ACS extends Appendable & CharSequence> void append(@org.jetbrains.annotations.NotNull @NotNull ACS sb, String str) {
try {
sb.append(str);
} catch (IOException e) {
......@@ -79,9 +87,9 @@ public class AppendableUtil {
}
}
public static void read8bitAndAppend(@NotNull StreamingDataInput bytes,
@NotNull StringBuilder appendable,
@NotNull StopCharsTester tester) throws IORuntimeException {
public static void read8bitAndAppend(@org.jetbrains.annotations.NotNull @NotNull StreamingDataInput bytes,
@org.jetbrains.annotations.NotNull @NotNull StringBuilder appendable,
@org.jetbrains.annotations.NotNull @NotNull StopCharsTester tester) {
while (true) {
int c = bytes.readUnsignedByte();
if (tester.isStopChar(c, bytes.peekUnsignedByte()))
......@@ -92,18 +100,21 @@ public class AppendableUtil {
}
}
public static void readUTFAndAppend(@NotNull StreamingDataInput bytes,
@NotNull Appendable appendable,
@NotNull StopCharsTester tester)
throws IOException, BufferUnderflowException {
public static void readUTFAndAppend(@org.jetbrains.annotations.NotNull @NotNull StreamingDataInput bytes,
@org.jetbrains.annotations.NotNull @NotNull Appendable appendable,
@org.jetbrains.annotations.NotNull @NotNull StopCharsTester tester)
throws BufferUnderflowException {
try {
readUtf8AndAppend(bytes, appendable, tester);
} catch (IOException e) {
throw new AssertionError(e);
}
}
public static void readUtf8AndAppend(@NotNull StreamingDataInput bytes,
@NotNull Appendable appendable,
@NotNull StopCharsTester tester)
throws IOException, BufferUnderflowException {
try {
public static void readUtf8AndAppend(@org.jetbrains.annotations.NotNull @NotNull StreamingDataInput bytes,
@org.jetbrains.annotations.NotNull @NotNull Appendable appendable,
@org.jetbrains.annotations.NotNull @NotNull StopCharsTester tester)
throws BufferUnderflowException, IOException {
while (true) {
int c = bytes.readUnsignedByte();
if (c >= 128) {
......@@ -117,8 +128,7 @@ public class AppendableUtil {
return;
}
while (true) {
int c = bytes.readUnsignedByte();
for (int c; (c = bytes.readUnsignedByte()) >= 0; ) {
switch (c >> 4) {
case 0:
case 1:
......@@ -140,7 +150,7 @@ public class AppendableUtil {
int char2 = bytes.readUnsignedByte();
if ((char2 & 0xC0) != 0x80)
throw new UTFDataFormatException(
"malformed input around byte");
"malformed input around byte " + Integer.toHexString(char2));
int c2 = (char) (((c & 0x1F) << 6) |
(char2 & 0x3F));
if (tester.isStopChar(c2, bytes.peekUnsignedByte()))
......@@ -154,9 +164,12 @@ public class AppendableUtil {
int char2 = bytes.readUnsignedByte();
int char3 = bytes.readUnsignedByte();
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
if (((char2 & 0xC0) != 0x80))
throw new UTFDataFormatException(
"malformed input around byte ");
"malformed input around byte " + Integer.toHexString(char2));
if ((char3 & 0xC0) != 0x80)
throw new UTFDataFormatException(
"malformed input around byte " + Integer.toHexString(char3));
int c3 = (char) (((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
(char3 & 0x3F));
......@@ -169,30 +182,30 @@ public class AppendableUtil {
default:
/* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException(
"malformed input around byte ");
}
"malformed input around byte " + Integer.toHexString(c));
}
} catch (IORuntimeException e) {
throw new IOException(e);
}
}
public static void parse8bit_SB1(@NotNull Bytes bytes, @NotNull StringBuilder sb, int utflen)
throws IORuntimeException, BufferUnderflowException {
public static void parse8bit_SB1(@org.jetbrains.annotations.NotNull @NotNull Bytes bytes, @org.jetbrains.annotations.NotNull @NotNull StringBuilder sb, int utflen)
throws BufferUnderflowException {
if (utflen > bytes.readRemaining())
throw new BufferUnderflowException();
NativeBytesStore nbs = (NativeBytesStore) bytes.bytesStore();
@Nullable NativeBytesStore nbs = (NativeBytesStore) bytes.bytesStore();
long offset = bytes.readPosition();
int count = BytesInternal.parse8bit_SB1(offset, nbs, sb, utflen);
bytes.readSkip(count);
}
public static void parse8bit(@NotNull StreamingDataInput bytes, Appendable appendable, int utflen)
throws IORuntimeException, BufferUnderflowException {
if (bytes instanceof Bytes
&& ((Bytes) bytes).bytesStore() instanceof NativeBytesStore
&& appendable instanceof StringBuilder) {
parse8bit_SB1((Bytes) bytes, (StringBuilder) appendable, utflen);
throws BufferUnderflowException, IOException {
if (appendable instanceof StringBuilder) {
@org.jetbrains.annotations.NotNull final StringBuilder sb = (StringBuilder) appendable;
if (bytes instanceof Bytes && ((Bytes) bytes).bytesStore() instanceof NativeBytesStore) {
parse8bit_SB1((Bytes) bytes, sb, utflen);
} else {
BytesInternal.parse8bit1(bytes, sb, utflen);
}
} else {
BytesInternal.parse8bit1(bytes, appendable, utflen);
}
......@@ -210,4 +223,102 @@ public class AppendableUtil {
throw new UnsupportedOperationException();
}
}
public static long findUtf8Length(@org.jetbrains.annotations.NotNull @NotNull CharSequence str) throws IndexOutOfBoundsException {
int strlen = str.length();
long utflen = strlen;/* use charAt instead of copying String to char array */
for (int i = 0; i < strlen; i++) {
char c = str.charAt(i);
if (c <= 0x007F) {
continue;
}
if (c <= 0x07FF) {
utflen++;
} else {
utflen += 2;
}
}
return utflen;
}
@Java9
public static long findUtf8Length(@org.jetbrains.annotations.NotNull @NotNull byte[] bytes, byte coder) {
long utflen;
if (coder == 0) {
int strlen = bytes.length;
utflen = bytes.length;
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < strlen; i++) {
int b = (bytes[i] & 0xFF);
if (b > 0x007F) {
utflen++;
}
}
} else {
int strlen = bytes.length;
utflen = 0;/* use charAt instead of copying String to char array */
for (int i = 0; i < strlen; i += 2) {
char c = (char) (((bytes[i + 1] & 0xFF) << 8) | (bytes[i] & 0xFF));
if (c <= 0x007F) {
utflen += 1;
continue;
}
if (c <= 0x07FF) {
utflen += 2;
} else {
utflen += 3;
}
}
}
return utflen;
}
@Java9
public static long findUtf8Length(@org.jetbrains.annotations.NotNull @NotNull byte[] chars) {
long utflen = 0; /* use charAt instead of copying String to char array */
int strlen = chars.length;
for (int i = 0; i < strlen; i++) {
int c = chars[i] & 0xFF; // unsigned byte
if (c == 0) { // we have hit end of string
break;
}
if (c >= 0xF0) {
utflen += 4;
i += 3;
} else if (c >= 0xE0) {
utflen += 3;
i += 2;
} else if (c >= 0xC0) {
utflen += 2;
i += 1;
} else {
utflen += 1;
}
}
return utflen;
}
public static long findUtf8Length(@org.jetbrains.annotations.NotNull @NotNull char[] chars) {
long utflen = chars.length;/* use charAt instead of copying String to char array */
for (char c : chars) {
if (c <= 0x007F) {
continue;
}
if (c <= 0x07FF) {
utflen++;
} else {
utflen += 2;
}
}
return utflen;
}
}
package net.openhft.chronicle.bytes;
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.util.AbstractInvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
public class BinaryBytesMethodWriterInvocationHandler extends AbstractInvocationHandler implements BytesMethodWriterInvocationHandler {
private final Function<Method, MethodEncoder> methodToId;
@SuppressWarnings("rawtypes")
private final BytesOut out;
private final Map<Method, MethodEncoder> methodToIdMap = new LinkedHashMap<>();
@SuppressWarnings("rawtypes")
public BinaryBytesMethodWriterInvocationHandler(Function<Method, MethodEncoder> methodToId, BytesOut out) {
super(HashMap::new);
this.methodToId = methodToId;
this.out = out;
}
@Override
protected Object doInvoke(Object proxy, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
MethodEncoder info = methodToIdMap.computeIfAbsent(method, methodToId);
if (info == null) {
Jvm.warn().on(getClass(), "Unknown method " + method + " ignored");
return null;
}
out.comment(method.getName());
out.writeStopBit(info.messageId());
info.encode(args, out);
return null;
}
}
/*
* Copyright (C) 2015 higherfrequencytrading.com
* Copyright 2016 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* http://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.bytes;
......@@ -20,19 +20,21 @@ import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.io.IORuntimeException;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.Writer;
import java.math.BigDecimal;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
/**
* Methods to append text to a Bytes. This extends the Appendable interface.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public interface ByteStringAppender<B extends ByteStringAppender<B>> extends StreamingDataOutput<B>, Appendable {
/**
* @return these Bytes as a Writer
*/
@NotNull
default Writer writer() {
return new ByteStringWriter(this);
}
......@@ -43,15 +45,11 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @param ch to append
* @return this
* @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded
* @throws IOException if an error occurred while attempting to resize the underlying buffer
*/
@Override
@NotNull
default B append(char ch) throws BufferOverflowException, IOException {
try {
default B append(char ch) throws BufferOverflowException {
BytesInternal.appendUtf8Char(this, ch);
} catch (IORuntimeException e) {
throw new IOException(e);
}
return (B) this;
}
......@@ -61,11 +59,42 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @param cs to append
* @return this
* @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded
* @throws IOException if an error occurred while attempting to resize the underlying buffer
*/
@Override
@NotNull
default B append(@NotNull CharSequence cs) throws BufferOverflowException, IOException {
default B append(@NotNull CharSequence cs) throws BufferOverflowException {
try {
return append(cs, 0, cs.length());
} catch (IndexOutOfBoundsException e) {
throw new AssertionError(e);
}
}
/**
* Append a boolean as T or F
*
* @param flag to append
* @return this
* @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B append(boolean flag) throws BufferOverflowException {
return append(flag ? 'T' : 'F');
}
/**
* Append an int in decimal
*
* @param value to append
* @return this
* @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B append(int value) throws BufferOverflowException {
BytesInternal.appendBase10(this, value);
return (B) this;
}
/**
......@@ -77,8 +106,29 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B append(long value) throws BufferOverflowException, IORuntimeException {
BytesInternal.append(this, value);
default B append(long value) throws BufferOverflowException {
if (value == (int) value)
BytesInternal.appendBase10(this, (int) value);
else
BytesInternal.appendBase10(this, value);
return (B) this;
}
@NotNull
default B appendBase(long value, int base) throws BufferOverflowException {
BytesInternal.append(this, value, base);
return (B) this;
}
@NotNull
default B appendBase16(long value) throws BufferOverflowException {
BytesInternal.appendBase16(this, value, 1);
return (B) this;
}
@NotNull
default B appendBase16(long value, int minDigits) throws BufferOverflowException {
BytesInternal.appendBase16(this, value, minDigits);
return (B) this;
}
......@@ -92,7 +142,7 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B appendDecimal(long value, int decimalPlaces) throws BufferOverflowException, IORuntimeException {
default B appendDecimal(long value, int decimalPlaces) throws BufferOverflowException {
BytesInternal.appendDecimal(this, value, decimalPlaces);
return (B) this;
}
......@@ -106,9 +156,14 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B append(float f) throws BufferOverflowException, IORuntimeException {
BytesInternal.append((StreamingDataOutput) this, f);
return (B) this;
default B append(float f) throws BufferOverflowException {
float f2 = Math.abs(f);
if (f2 > 1e6 || f2 < 1e-3) {
return append(Float.toString(f));
}
int precision = (int) Math.floor(6 - Math.log10(f2));
long tens = Maths.tens(precision);
return append((double) Math.round(f * tens) / tens);
}
/**
......@@ -120,14 +175,14 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B append(double d) throws BufferOverflowException, IORuntimeException {
BytesInternal.append((StreamingDataOutput) this, d);
default B append(double d) throws BufferOverflowException {
BytesInternal.append(this, d);
return (B) this;
}
/**
* Append a double in decimal notation to a specific number of decimal places. Trailing zeros are not truncated.
* <p/>
* <p>
* If the number would normally be printed with more decimal places, the number is rounded.
*
* @param d to append
......@@ -137,11 +192,15 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B append(double d, int decimalPlaces) throws BufferOverflowException, IORuntimeException {
default B append(double d, int decimalPlaces) throws BufferOverflowException {
if (decimalPlaces < 0)
throw new IllegalArgumentException();
if (decimalPlaces < 20) {
double d2 = d * Maths.tens(decimalPlaces);
if (d2 <= Long.MAX_VALUE && d2 >= Long.MIN_VALUE) {
return appendDecimal(Math.round(d2), decimalPlaces);
// changed from java.lang.Math.round(d2) as this was shown up to cause latency
long round = d2 > 0.0 ? (long) (d2 + 0.5) : (long) (d2 - 0.5);
return appendDecimal(round, decimalPlaces);
}
}
return append(d);
......@@ -155,16 +214,12 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @param end index of the last char exclusive.
* @return this
* @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded
* @throws IOException if an error occurred while attempting to resize the underlying buffer
*/
@Override
@NotNull
default B append(@NotNull CharSequence cs, int start, int end)
throws IndexOutOfBoundsException, BufferOverflowException, IOException {
try {
throws IndexOutOfBoundsException, BufferOverflowException {
BytesInternal.appendUtf8(this, cs, start, end - start);
} catch (IORuntimeException e) {
throw new IOException(e);
}
return (B) this;
}
......@@ -175,21 +230,16 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @return this
* @throws BufferOverflowException If the string as too large to write in the capacity available
* @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
*/
@NotNull
default B append8bit(@NotNull CharSequence cs)
throws BufferOverflowException, BufferUnderflowException, IORuntimeException {
if (cs instanceof BytesStore) {
return write((BytesStore) cs);
throws BufferOverflowException, BufferUnderflowException, IndexOutOfBoundsException {
return append8bit(cs, 0, cs.length());
}
int length = cs.length();
for (int i = 0; i < length; i++) {
char c = cs.charAt(i);
if (c > 255) c = '?';
writeByte((byte) c);
}
return (B) this;
default B append8bit(@NotNull String cs)
throws BufferOverflowException, BufferUnderflowException, IndexOutOfBoundsException {
return append8bit(cs, 0, cs.length());
}
/**
......@@ -201,11 +251,10 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
* @return this
* @throws BufferOverflowException If the string as too large to write in the capacity available
* @throws BufferUnderflowException if the capacity of the underlying buffer was exceeded
* @throws IORuntimeException if an error occurred while attempting to resize the underlying buffer
* @throws IndexOutOfBoundsException if the start or the end are not valid for the CharSequence
*/
default B append8bit(@NotNull CharSequence cs, int start, int end)
throws IllegalArgumentException, BufferOverflowException, BufferUnderflowException, IndexOutOfBoundsException, IORuntimeException {
throws IllegalArgumentException, BufferOverflowException, BufferUnderflowException, IndexOutOfBoundsException {
if (cs instanceof BytesStore) {
return write((BytesStore) cs, (long) start, end);
}
......@@ -217,13 +266,21 @@ public interface ByteStringAppender<B extends ByteStringAppender<B>> extends Str
return (B) this;
}
@NotNull
default B appendDateMillis(long dateInMillis) {
BytesInternal.appendDateMillis(this, dateInMillis);
return (B) this;
}
@NotNull
default B appendTimeMillis(long timeOfDayInMillis) {
BytesInternal.appendTimeMillis(this, timeOfDayInMillis % 86400_000L);
return (B) this;
}
@NotNull
default B append(@NotNull BigDecimal bigDecimal) {
append(bigDecimal.toString());
return (B) this;
}
}
/*
* Copyright (C) 2015 higherfrequencytrading.com
* Copyright 2016 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* http://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.bytes;
import net.openhft.chronicle.core.Maths;
import net.openhft.chronicle.core.annotation.ForceInline;
import net.openhft.chronicle.core.io.IORuntimeException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.Reader;
import java.nio.BufferOverflowException;
import java.math.BigDecimal;
import java.nio.BufferUnderflowException;
/**
......@@ -33,6 +35,7 @@ interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataI
*
* @return as a Reader
*/
@NotNull
default Reader reader() {
return new ByteStringReader(this);
}
......@@ -40,18 +43,24 @@ interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataI
/**
* Return true or false, or null if it could not be detected
* as true or false. Case is not important
* <p/>
* <p>
* <p>false: f, false, n, no, 0
* <p/>
* <p>
* <p>true: t, true, y, yes, 1
*
* @param tester to detect the end of the text.
* @return true, false, or null if neither.
*/
@Nullable
default Boolean parseBoolean(@NotNull StopCharTester tester) {
return BytesInternal.parseBoolean(this, tester);
}
@Nullable
default Boolean parseBoolean() {
return BytesInternal.parseBoolean(this, StopCharTesters.NON_ALPHA_DIGIT);
}
/**
* parse text with UTF-8 decoding as character terminated.
*
......@@ -64,6 +73,7 @@ interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataI
return BytesInternal.parseUtf8(this, stopCharTester);
}
@NotNull
@Deprecated
default String parseUTF(@NotNull StopCharTester stopCharTester) {
return parseUtf8(stopCharTester);
......@@ -76,12 +86,12 @@ interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataI
* @param stopCharTester to check if the end has been reached.
*/
@ForceInline
default void parseUtf8(@NotNull Appendable buffer, @NotNull StopCharTester stopCharTester) {
default void parseUtf8(@NotNull Appendable buffer, @NotNull StopCharTester stopCharTester) throws BufferUnderflowException {
BytesInternal.parseUtf8(this, buffer, stopCharTester);
}
@Deprecated
default void parseUTF(@NotNull Appendable buffer, @NotNull StopCharTester stopCharTester) {
default void parseUTF(@NotNull Appendable buffer, @NotNull StopCharTester stopCharTester) throws BufferUnderflowException {
parseUtf8(buffer, stopCharTester);
}
......@@ -93,13 +103,13 @@ interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataI
*/
@ForceInline
default void parseUtf8(@NotNull Appendable buffer, @NotNull StopCharsTester stopCharsTester)
throws BufferUnderflowException, BufferOverflowException, IORuntimeException {
throws BufferUnderflowException, IORuntimeException {
BytesInternal.parseUtf8(this, buffer, stopCharsTester);
}
@Deprecated
default void parseUTF(@NotNull Appendable buffer, @NotNull StopCharsTester stopCharsTester)
throws BufferUnderflowException, BufferOverflowException, IORuntimeException {
throws BufferUnderflowException, IORuntimeException {
parseUtf8(buffer, stopCharsTester);
}
......@@ -109,59 +119,101 @@ interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataI
* @param buffer to populate
* @param stopCharTester to check if the end has been reached.
*/
@SuppressWarnings("rawtypes")
@ForceInline
default void parse8bit(Appendable buffer, @NotNull StopCharTester stopCharTester)
throws BufferUnderflowException, BufferOverflowException, IORuntimeException {
throws BufferUnderflowException {
if (buffer instanceof StringBuilder)
BytesInternal.parse8bit(this, (StringBuilder) buffer, stopCharTester);
else
BytesInternal.parse8bit(this, (Bytes) buffer, stopCharTester);
}
/**
* parse text with ISO-8859-1 decoding as character terminated.
*
* @param stopCharTester to check if the end has been reached.
*/
default String parse8bit(@NotNull StopCharTester stopCharTester)
throws BufferUnderflowException {
return BytesInternal.parse8bit(this, stopCharTester);
}
/**
* parse text with ISO-8859-1 decoding as character terminated.
*
* @param buffer to populate
* @param stopCharsTester to check if the end has been reached.
*/
@SuppressWarnings("rawtypes")
@ForceInline
default void parse8bit(Appendable buffer, @NotNull StopCharsTester stopCharsTester)
throws BufferUnderflowException, BufferOverflowException, IORuntimeException {
throws BufferUnderflowException {
if (buffer instanceof StringBuilder)
BytesInternal.parse8bit(this, (StringBuilder) buffer, stopCharsTester);
else
BytesInternal.parse8bit(this, (Bytes) buffer, stopCharsTester);
}
@SuppressWarnings("rawtypes")
default void parse8bit(Bytes buffer, @NotNull StopCharsTester stopCharsTester)
throws BufferUnderflowException {
BytesInternal.parse8bit(this, buffer, stopCharsTester);
}
default void parse8bit(StringBuilder buffer, @NotNull StopCharsTester stopCharsTester)
throws BufferUnderflowException {
BytesInternal.parse8bit(this, buffer, stopCharsTester);
}
/**
* parse text as an int. The terminating character is consumed.
*
* @return an int.
*/
@ForceInline
default int parseInt() throws BufferUnderflowException {
return Maths.toInt32(BytesInternal.parseLong(this));
}
/**
* parse text as a long integer. The terminating character is consumed.
*
* @return a long.
*/
@ForceInline
default long parseLong() throws BufferUnderflowException, IORuntimeException {
default long parseLong() throws BufferUnderflowException {
return BytesInternal.parseLong(this);
}
/**
* parse text as a float decimal. The terminating character is consumed.
* <p>
* The number of decimal places can be retrieved with lastDecimalPlaces()
*
* @return a float.
*/
default float parseFloat() throws BufferUnderflowException {
return (float) BytesInternal.parseDouble(this);
}
/**
* parse text as a double decimal. The terminating character is consumed.
* <p/>
* <p>
* The number of decimal places can be retrieved with lastDecimalPlaces()
*
* @return a double.
*/
@ForceInline
default double parseDouble() throws BufferUnderflowException, IORuntimeException {
default double parseDouble() throws BufferUnderflowException {
return BytesInternal.parseDouble(this);
}
/**
* Parse the significant digits of a decimal number.
* <p/>
* <p>
* The number of decimal places can be retrieved with lastDecimalPlaces()
*
* @return the significant digits
* @throws BufferUnderflowException
*/
default long parseLongDecimal() throws BufferUnderflowException {
return BytesInternal.parseLongDecimal(this);
......@@ -186,7 +238,13 @@ interface ByteStringParser<B extends ByteStringParser<B>> extends StreamingDataI
* @return true if a terminating character was found, false if the end of the buffer was reached.
*/
@ForceInline
default boolean skipTo(@NotNull StopCharTester tester) throws IORuntimeException {
default boolean skipTo(@NotNull StopCharTester tester) {
return BytesInternal.skipTo(this, tester);
}
@NotNull
default BigDecimal parseBigDecimal() {
return new BigDecimal(parseUtf8(StopCharTesters.NUMBER_END));
}
}
/*
* Copyright (C) 2015 higherfrequencytrading.com
* Copyright 2016 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* http://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.bytes;
import net.openhft.chronicle.core.io.IORuntimeException;
import java.io.IOException;
import java.io.Reader;
import java.nio.BufferUnderflowException;
......@@ -25,6 +23,7 @@ import java.nio.BufferUnderflowException;
/**
* A Reader wrapper for Bytes. This Reader moves the readPosition() of the underlying Bytes up to the readLimit()
*/
@SuppressWarnings("rawtypes")
public class ByteStringReader extends Reader {
private final ByteStringParser in;
......@@ -33,12 +32,8 @@ public class ByteStringReader extends Reader {
}
@Override
public int read() throws IOException {
try {
public int read() {
return in.readRemaining() > 0 ? in.readUnsignedByte() : -1;
} catch (IORuntimeException e) {
throw new IOException(e);
}
}
@Override
......@@ -46,7 +41,8 @@ public class ByteStringReader extends Reader {
long len = Math.min(in.readRemaining(), n);
try {
in.readSkip(len);
} catch (BufferUnderflowException | IORuntimeException e) {
} catch (BufferUnderflowException e) {
throw new IOException(e);
}
return len;
......@@ -56,7 +52,8 @@ public class ByteStringReader extends Reader {
public int read(char[] cbuf, int off, int len) throws IOException {
try {
return in.read(cbuf, off, len);
} catch (IORuntimeException e) {
} catch (BufferUnderflowException e) {
throw new IOException(e);
}
}
......
/*
* Copyright (C) 2015 higherfrequencytrading.com
* Copyright 2016 higherfrequencytrading.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* http://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.openhft.chronicle.bytes;
import net.openhft.chronicle.core.io.IORuntimeException;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.Writer;
......@@ -25,18 +25,20 @@ import java.nio.BufferOverflowException;
/**
* A Writer for an underlying Bytes. This moves the writePosition() up to the writeLimit();
*/
public class ByteStringWriter extends Writer {
@SuppressWarnings("rawtypes")
class ByteStringWriter extends Writer {
private final ByteStringAppender out;
public ByteStringWriter(ByteStringAppender out) {
ByteStringWriter(ByteStringAppender out) {
this.out = out;
}
@Override
public void write(int c) throws IOException {
try {
out.append(c);
} catch (BufferOverflowException | IllegalArgumentException | IORuntimeException e) {
out.append((char) c);
} catch (@NotNull BufferOverflowException e) {
throw new IOException(e);
}
}
......@@ -47,22 +49,25 @@ public class ByteStringWriter extends Writer {
}
@Override
public void write(String str, int off, int len) throws IndexOutOfBoundsException, IOException {
public void write(String str, int off, int len) throws IOException {
out.append(str, off, off + len);
}
@NotNull
@Override
public Writer append(CharSequence csq) throws IOException {
public Writer append(@NotNull CharSequence csq) throws IOException {
out.append(csq);
return this;
}
@NotNull
@Override
public Writer append(CharSequence csq, int start, int end) throws IndexOutOfBoundsException, IOException {
public Writer append(@NotNull CharSequence csq, int start, int end) throws IOException {
out.append(csq, start, end);
return this;
}
@NotNull
@Override
public Writer append(char c) throws IOException {
out.append(c);
......