package abstrasy.libraries.io;
import abstrasy.Bivalence;
import abstrasy.Buffer;
import abstrasy.Bytes;
import abstrasy.Node;
import abstrasy.SELF;
import abstrasy.externals.AExtCachable;
import abstrasy.externals.AExtClonable;
import abstrasy.externals.AExtTools;
import abstrasy.externals.AExtVObject;
import abstrasy.externals.OptAccess;
import abstrasy.externals.OptAccessList;
import abstrasy.externals.OptAccessProvider;
import abstrasy.interpreter.ORef;
import abstrasy.libraries.math.External_Integer;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.zip.CRC32;
/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
* http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/
public class External_Buffer extends OptAccessProvider
implements AExtClonable,AExtCachable,AExtVObject {
private Buffer buffer = new Buffer();
/*
* ---------------------------------------------------------------------------------
*
* Gestion des options
* ===================
*
* 'charset:
* Quel est l'encodage des caractères du buffer. Par défaut, il s'agit de
* l'encodage du système d'exploitation.
*/
private OptAccess oa_charset = new OptAccess("charset") {
public Node getNode() {
return buffer.getCharset() == null ? Node.createNothing(): new Node(buffer.getCharset());
}
public void setNode(Node optNode) throws Exception {
optNode.requireNodeType(Node.TYPE_STRING);
buffer.setCharset(optNode.getString());
}
};
/*
* ---------------------------------------------------------------------------------
*/
public External_Buffer() {
this.setOptAccessList(new OptAccessList(oa_charset));
}
/**
* Modifier la taille fixe du tampon.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_set_fixed_size(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.setFixedSize((int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber());
return null;
}
/**
* Récupérer la taille fixe du tampon du tampon.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_get_fixed_size(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.getFixedSize());
}
/**
* Fixer le tampon en fonction de sa taille fixe.
*
* Si un argument est fourni, il s'agit de la taille fixe du tampon en octets.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_pack(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1, 2);
SELF.require_SELF_mutable();
if (startAt.size() == 2)
buffer.setFixedSize((int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber());
buffer.pack();
return null;
}
/**
* Sauter les octets null (0x00).
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_trim_null(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
buffer.trim_null();
return null;
}
public Node external_mutator_poke(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
byte data = (byte) startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
buffer.poke(rel_pos, data);
return null;
}
public Node external_peek(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek(rel_pos));
}
public Node external_mutator_poke_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
short data = (short) startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
buffer.poke_short(rel_pos, data);
return null;
}
public Node external_peek_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek_short(rel_pos));
}
public Node external_mutator_poke_unsigned_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
int data = (int) startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
buffer.poke_unsigned_short(rel_pos, data);
return null;
}
public Node external_peek_unsigned_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek_unsigned_short(rel_pos));
}
public Node external_mutator_poke_int(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
int data = (int) startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
buffer.poke_int(rel_pos, data);
return null;
}
public Node external_peek_int(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek_int(rel_pos));
}
public Node external_mutator_poke_long(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
long data = (long) startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
buffer.poke_long(rel_pos, data);
return null;
}
public Node external_peek_long(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek_long(rel_pos));
}
public Node external_mutator_poke_float(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
float data = (float) startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
buffer.poke_float(rel_pos, data);
return null;
}
public Node external_peek_float(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek_float(rel_pos));
}
public Node external_mutator_poke_double(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
double data = startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
buffer.poke_double(rel_pos, data);
return null;
}
public Node external_peek_double(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek_double(rel_pos));
}
public Node external_mutator_poke_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
Buffer data = ((External_Buffer) AExtTools.getArgExternalInstance(startAt, 2, External_Buffer.class, Node.ACCESSVTYPE_MUTABLE_WRITELOCK)).buffer;
buffer.poke_buffer(rel_pos, data);
return null;
}
public Node external_peek_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
int rel_len = (int) startAt.getSubNode(2, Node.TYPE_NUMBER).getNumber();
External_Buffer res = new External_Buffer();
res.buffer = buffer.peek_buffer(rel_pos, rel_len);
res.buffer.setCharset(buffer.getCharset());
return Node.createExternal(res);
}
public Node external_mutator_poke_utf(Node startAt) throws Exception {
startAt.isGoodArgsCnt(3);
SELF.require_SELF_mutable();
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
String data = startAt.getSubNode(2, Node.TYPE_STRING).getString();
buffer.poke_utf(rel_pos, data);
return null;
}
public Node external_peek_utf(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
int rel_pos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
return new Node(buffer.peek_utf(rel_pos));
}
/**
* Ce prédicat permet de savoir su le buffer est inscriptible.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_is_writable(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.isWritable() ? Node.TRUE: Node.FALSE);
}
/**
* Ce prédicat permet de savoir su le buffer est lisible.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_is_readable(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.isReadable() ? Node.TRUE: Node.FALSE);
}
/**
* Permet de rendre un buffer inscriptible.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_make_writable(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
buffer.makeWritable();
return null;
}
/**
* Renvoie la taille du tampon actuelle.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_length(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.length());
}
/**
* Nettoyage du buffer. Celui-ci est réinitialisé.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_clear(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
buffer.clear();
return null;
}
/**
* Compression GZ du contenu du buffer.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_compress(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
buffer.compress();
return null;
}
/**
* Décompression GZ du contenu du buffer.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_decompress(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
buffer.decompress();
return null;
}
/**
* Lecture à partir d'une chaîne de caractères hexadécimales.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_from_hex_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.fromHexString(startAt.getSubNode(1, Node.TYPE_STRING).getString());
return null;
}
/**
* convertir le contenu en une chaîne de caractères hexadécimales.
* @param startAt
* @return
* @throws Exception
*/
public Node external_hex_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.length() > 0 ? buffer.toHexString(): "");
}
/**
* Lecture à partir d'une chaîne de caractères encodée en base64.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_from_base64_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.fromBase64String(startAt.getSubNode(1, Node.TYPE_STRING).getString());
return null;
}
/**
* convertir le contenu en une chaîne de caractères encodée en base64.
* @param startAt
* @return
* @throws Exception
*/
public Node external_base64_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.length() > 0 ? buffer.toBase64String(): "");
}
/**
* Retrourne un Math:Integer représentant le MD5 du contenu de buffer.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_md5(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
byte[] h0=MessageDigest.getInstance("MD5").digest(buffer.getArray());
byte[] h1=new byte[h0.length+1];
h1[0]=0;
for(int i=0;i<h0.length;i++)
h1[i+1]=h0[i];
BigInteger bint= new BigInteger(h1);
External_Integer res=new External_Integer(bint);
return Node.createExternal(res);
}
/**
* Retrourne un Math:Integer représentant le SHA1 du contenu de buffer.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_sha1(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
byte[] h0=MessageDigest.getInstance("SHA1").digest(buffer.getArray());
byte[] h1=new byte[h0.length+1];
h1[0]=0;
for(int i=0;i<h0.length;i++)
h1[i+1]=h0[i];
BigInteger bint= new BigInteger(h1);
External_Integer res=new External_Integer(bint);
return Node.createExternal(res);
}
/**
* Retrourne un Math:Integer représentant le CRC32 du contenu de buffer.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_crc32(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
CRC32 crc = new CRC32();
crc.update(buffer.getArray());
long h0=crc.getValue();
BigInteger bint= BigInteger.valueOf(h0);
External_Integer res=new External_Integer(bint);
return Node.createExternal(res);
}
/**
* convertir le contenu en une chaîne de caractères urlencodée en UTF-8.
* @param startAt
* @return
* @throws Exception
*/
public Node external_urlencode_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.length() > 0 ? buffer.toURLEncodeString(): "");
}
public Node external_quoted_printable_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1, 2);
if (startAt.size() == 1) {
return new Node(buffer.length() > 0 ? buffer.toQuotedPrintableString(): "");
}
else {
int len = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
if (len <= 0)
throw new Error("out of range(modulo(" + len + ") must be > 0");
return new Node(buffer.length() > 0 ? buffer.toQuotedPrintableString(len): "");
}
}
public Node external_q_encoded_word_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.length() > 0 ? buffer.toQEncodedWordString(): "");
}
public Node external_b64_encoded_word_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.length() > 0 ? buffer.toB64EncodedWordString(): "");
}
public Node external_mutator_from_quoted_printable_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.fromQuotedPrintableString(startAt.getSubNode(1, Node.TYPE_STRING).getString());
return null;
}
public Node external_mutator_from_encoded_word_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.fromEncodedWordString(startAt.getSubNode(1, Node.TYPE_STRING).getString());
return null;
}
/**
* convertir le contenu en une chaîne de caractères 'printable'.
* @param startAt
* @return
* @throws Exception
*/
public Node external_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return new Node(buffer.length() > 0 ? buffer.toString(): "");
}
public Node external_bytes(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
return Node.createBytes(new Bytes(buffer.getArray()));
}
/**
* convertir le contenu en une chaîne de caractères 'printable'.
* @param startAt
* @return
* @throws Exception
*/
public Node external_printable_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
StringBuilder r = new StringBuilder();
for (int i = 0; i < buffer.length(); ) {
byte c = buffer.peek(i++);
if (c >= 32 && c < 127)
r.append((char) c);
else
r.append(' ');
}
return new Node(r.length() > 0 ? r.toString(): "");
}
/**
* Découpe le buffer actuel et retourne une liste de buffers. La découpe
* correspond à des section de sous-buffers. On fournit le buffer dont le
* contenu délimite les sections.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_split_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
Buffer match = ((External_Buffer) AExtTools.getArgExternalInstance(startAt, 1, External_Buffer.class, Node.ACCESSVTYPE_MUTABLE_WRITELOCK)).buffer;
if (match.length() == 0)
throw new Exception("sought buffer cannot be empty");
ArrayList<Buffer> parts = buffer.split_array(match.getArray());
//System.out.println("parts:"+parts.size());
Node res = Node.createCList();
for (int i = 0; i < parts.size(); i++) {
External_Buffer part = new External_Buffer();
part.setBuffer(parts.get(i));
part.getBuffer().setCharset(buffer.getCharset());
res.addElement(Node.createExternal(part));
}
return res;
}
/**
* Découpe le buffer actuel et retourne une liste de buffers. La découpe
* correspond à des section mime/multipart. On fournit donc une chaîne
* de caractères. Celle-ci constitue la chaîne 'boundary' qui délimite
* les sections.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_split_multipart(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
String boundaryStr = startAt.getSubNode(1, Node.TYPE_STRING).getString();
if (boundaryStr.length() == 0)
throw new Exception("Boundary cannot be an empty string");
ArrayList<Buffer> parts = buffer.split_multipart(boundaryStr.getBytes());
//System.out.println("parts:"+parts.size());
Node res = Node.createCList();
for (int i = 0; i < parts.size(); i++) {
External_Buffer part = new External_Buffer();
part.setBuffer(parts.get(i));
part.getBuffer().setCharset(buffer.getCharset());
res.addElement(Node.createExternal(part));
}
return res;
}
/**
* Trouve la position index(offset) du prochain segment du buffer courant qui correspond au buffer
* recherché. Si le buffer recherché n'est pas trouvé, la méthode retourne -1.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_offset_of_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2, 3);
Buffer match = ((External_Buffer) AExtTools.getArgExternalInstance(startAt, 1, External_Buffer.class, Node.ACCESSVTYPE_MUTABLE_WRITELOCK)).buffer;
int spos = 0;
if (startAt.size() == 3)
spos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
if (match.length() == 0)
throw new Exception("sought buffer cannot be empty");
if (match.length() > buffer.length())
return new Node(-1);
return new Node(buffer.find_array(match.getArray(), spos));
}
/**
* Trouve la position index(offset) du prochain segment du buffer courant qui correspond à
* la chaîne recherchée. La conversion de caractères est fixée par le buffer courant.
* Si la chaîne n'est pas trouvée, la méthode retourne -1.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_offset_of_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2, 3);
String match = startAt.getSubNode(1, Node.TYPE_STRING).getString();
int spos = 0;
if (startAt.size() == 3)
spos = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
if (match.length() == 0)
throw new Exception("sought string cannot be empty");
byte[] bmatch = match.getBytes(buffer.getCharset());
if (bmatch.length + spos > buffer.length())
return new Node(-1);
return new Node(buffer.find_array(bmatch, spos));
}
/**
* Lecture à partir d'une chaîne de caractères urlencodée en UTF-8.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_from_urlencode_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.fromURLEncodeString(startAt.getSubNode(1, Node.TYPE_STRING).getString());
return null;
}
/**
* Sérialisation du buffer...
* @param startAt
* @return
* @throws Exception
*/
public Node external_quote(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1, 2);
Node res = null;
res = AExtTools.createNewExpr(Node.createSymbol("Io:Buffer"), Node.createLazy().append(AExtTools.createSExpression(":from-base64-string!", new Node[] { new Node(buffer.length() > 0 ?
buffer.toBase64String(): "") })).append(AExtTools.createSExpression(":set-charset", new Node[] { new Node(buffer.getCharset()) }))
.append(AExtTools.createSExpression(":set-fixed-size", new Node[] { new Node(buffer.getFixedSize()) })));
return res;
}
/**
* interne toString()...
* @return
*/
public String toString() {
String res = "<" + super.toString() + ">:" + buffer.toHexString();
return res;
}
/**
* clonage à partir de Node.
* @param bival
* @return
* @throws Exception
*/
public Object clone_my_self(Bivalence bival) throws Exception {
//System.out.println("Buffer cloned "+this);
External_Buffer te = new External_Buffer();
te.setBuffer(buffer.duplicate());
return te;
}
/**
* Ecriture d'un byte dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_byte(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_byte((byte) Math.round(startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber()));
return null;
}
/**
* Ecriture d'un short dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_short((short) Math.round(startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber()));
return null;
}
/**
* Ecriture d'un short non signé dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_unsigned_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_unsigned_short((int) Math.round(startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber()));
return null;
}
/**
* Ecriture d'un int dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_int(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_int((int) Math.round(startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber()));
return null;
}
/**
* Ecriture d'un long dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_long(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_long(Math.round(startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber()));
return null;
}
/**
* Ecriture d'un float dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_float(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_float((float) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber());
return null;
}
/**
* Ecriture d'un double dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_double(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_double(startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber());
return null;
}
/**
* Ecriture d'un Buffer dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_Buffer(((External_Buffer) AExtTools.getArgExternalInstance(startAt, 1, External_Buffer.class, Node.ACCESSVTYPE_MUTABLE_WRITELOCK)).buffer);
return null;
}
/**
* Ecriture d'une chaîne de caractères dans le dans le tampon (en utilisant l'encodage charset du Buffer).
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_string(Node startAt) throws Exception {
SELF.require_SELF_mutable();
StringBuilder ws = new StringBuilder();
for (int i = 1; i < startAt.size(); i++) {
ws.append(Node.node2VString(startAt.getSubNode(i, Node.VTYPE_VALUABLE)).getString());
}
buffer.write_string(ws.toString());
return null;
}
public Node external_mutator_write_mime_header(Node startAt) throws Exception {
SELF.require_SELF_mutable();
StringBuilder ws = new StringBuilder();
for (int i = 1; i < startAt.size();) {
ws.append(Node.node2VString(startAt.getSubNode(i++, Node.VTYPE_VALUABLE)).getString());
}
buffer.write_mime_header(ws.toString());
return null;
}
/**
* Ecriture d'une chaîne de caractères dans le dans le tampon (en utilisant l'encodage charset du Buffer).
* Le caractère NL(10) est ajouté à la suite de la chaîne.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_line(Node startAt) throws Exception {
SELF.require_SELF_mutable();
StringBuilder ws = new StringBuilder();
for (int i = 1; i < startAt.size();) {
ws.append(Node.node2VString(startAt.getSubNode(i++, Node.VTYPE_VALUABLE)).getString());
}
ws.append('\n');
buffer.write_string(ws.toString());
return null;
}
/**
* Ecriture d'une chaîne de caractères dans le dans le tampon (en utilisant l'encodage charset du Buffer).
* Les caractères CR(13)NL(10) sont ajoutés à la suite de la chaîne.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_crln(Node startAt) throws Exception {
SELF.require_SELF_mutable();
StringBuilder ws = new StringBuilder();
for (int i = 1; i < startAt.size();) {
ws.append(Node.node2VString(startAt.getSubNode(i++, Node.VTYPE_VALUABLE)).getString());
}
ws.append("\r\n");
buffer.write_string(ws.toString());
return null;
}
/**
* Ecriture d'un chunked Buffer dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_chunked_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(2);
SELF.require_SELF_mutable();
buffer.write_chunked_Buffer(((External_Buffer) AExtTools.getArgExternalInstance(startAt, 1, External_Buffer.class, Node.ACCESSVTYPE_MUTABLE_WRITELOCK)).buffer);
return null;
}
/**
* Ecriture d'une chaîne de caractères dans un segment chunked dans le tampon (en utilisant l'encodage charset du Buffer).
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_chunked_string(Node startAt) throws Exception {
SELF.require_SELF_mutable();
StringBuilder ws = new StringBuilder();
for (int i = 1; i < startAt.size(); i++) {
ws.append(Node.node2VString(startAt.getSubNode(i, Node.VTYPE_VALUABLE)).getString());
}
buffer.write_chunked_string(ws.toString());
return null;
}
/**
* Ecriture d'une chaîne de caractères UTF-8 dans un segment chunked dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_write_UTF(Node startAt) throws Exception {
SELF.require_SELF_mutable();
StringBuilder ws = new StringBuilder();
for (int i = 1; i < startAt.size(); i++) {
ws.append(Node.node2VString(startAt.getSubNode(i, Node.VTYPE_VALUABLE)).getString());
}
buffer.write_UTF(ws.toString());
return null;
}
/**
* Lecture d'un byte dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_byte(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_byte());
}
/**
* Lecture d'un short dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_short());
}
/**
* Lecture d'un unsigned-short dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_unsigned_short(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_unsigned_short());
}
/**
* Lecture d'un int dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_int(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_int());
}
/**
* Lecture d'un long dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_long(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_long());
}
/**
* Lecture d'un float dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_float(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_float());
}
/**
* Lecture d'un double dans le tampon.
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_double(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_double());
}
/**
* Lecture d'un buffer à partir du tampon.
* On peut fournir un paramètre optionnel fournissant le nombre de bytes à lire
* pour constituer le nouveau tampon.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1, 2);
SELF.require_SELF_mutable();
int sz = buffer.length();
if (startAt.size() == 2) {
sz = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
}
External_Buffer res = new External_Buffer();
res.buffer = buffer.read_Buffer(sz);
res.buffer.setCharset(buffer.getCharset());
return Node.createExternal(res);
}
/**
* Lecture d'une chaîne de caractère à partir dutampon.
* On peut fournir un paramètre optionnel fournissant le nombre de bytes à lire
* pour constituer le nouveau tampon.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1, 2);
SELF.require_SELF_mutable();
int sz = buffer.length();
if (startAt.size() == 2) {
sz = (int) startAt.getSubNode(1, Node.TYPE_NUMBER).getNumber();
}
return new Node(buffer.read_string(sz));
}
/**
* Lecture d'une chaîne de caractère à partir du tampon jusqu'au prochian
* caractère NL(10). Celui-ci est inclu dans la chaîne lue qui est retournée
* brute.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_line(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_line());
}
/**
* Lecture d'une chaîne de caractère à partir du tampon jusqu'à la prochaine
* séquence de caractères CR(13)NL(10). Ceux-ci sont inclus dans la chaîne lue
* qui est retournée brute.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_crln(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_crln());
}
/**
* Lit dans le buffer la prochaine en-tête MIME (en-têtes multi-lignes supportées) et
* la retourne sous al forme d'une chaîne de caractères nettoyée (c-à-d dire, barrassée
* des caractères d'espacement inutile et des retours à la ligne. La forme retournée
* est uniligne. Lorsqu'il n'y a plus d'en-tête à lire, la méthode retourne NOTHING.
*
* Attention, si on dépasse la fin de la liste d'en-têtes (une ligne vide - uniquement
* <CR><LN>), on peut obtenir n'importe quoi parce que la méthode cherchera au delà.
* (IETF:rfc2046).
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_mime_header(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
String mimeh = buffer.read_mime_header();
return mimeh.length() > 0 ? new Node(mimeh): Node.createNothing();
}
/**
* Lecture d'un chunked buffer à partir du tampon.
* On peut fournir un paramètre optionnel fournissant le nombre de bytes à lire
* pour constituer le nouveau tampon.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_chunked_buffer(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
External_Buffer res = new External_Buffer();
res.buffer = buffer.read_chunked_Buffer();
res.buffer.setCharset(buffer.getCharset());
return Node.createExternal(res);
}
/**
* Lecture d'une chaîne de caractère à partir d'un segment chunked du tampon.
* On peut fournir un paramètre optionnel fournissant le nombre de bytes à lire
* pour constituer le nouveau tampon.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_chunked_string(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_chunked_string());
}
/**
* Lecture d'une chaîne de caractère UTF à partir d'un segment chunked du tampon.
*
* @param startAt
* @return
* @throws Exception
*/
public Node external_mutator_read_UTF(Node startAt) throws Exception {
startAt.isGoodArgsCnt(1);
SELF.require_SELF_mutable();
return new Node(buffer.read_UTF());
}
public void setBuffer(Buffer buffer) {
this.buffer = buffer;
}
public Buffer getBuffer() {
return buffer;
}
/*
* ----------------------------------------------------------------------------
*
* Optimisation par cache d'instanciantion (mars 2012) rev 1.0-6321.0
*
* ----------------------------------------------------------------------------
*/
private static ORef _optim_symbols_cache_ = new ORef();
@Override
public Object getSymbolsCache() {
return _optim_symbols_cache_.getRef();
}
@Override
public void setSymbolsCache(Object cache) {
_optim_symbols_cache_.setRef(cache);
}
}