Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  chap10_mj.html   Sprache: HTML

 

 products/Sources/formale Sprachen/GAP/pkg/io/doc/chap10_mj.html


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://45, 50, 52, 53, 55  ,

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<title>GAP (IO) - Chapter 10: Examples of usage</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
nual..js" type="ext/javascript></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap10"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="chap11_mj.html">11</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<div class="chlinkprevnexttop"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap9_mj.html">[Previous Chapter]</a>    <a href="chap11_mj.html">[Next Chapter]</a>   </div>

<p id="mathjaxlink" class="pcenter"><a href="chap10.html">[MathJax off]</a></p>
<p><a id="X7EADF566874177D8" name="X7EADF566874177D8"></a></p>
<div class="ChapSects"><a href="chap10_mj.html#X7EADF566874177D8">10 <span class="Heading">Examples of usage</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X7EC25CA68794860A">10.1 <span class="Heading">Writing and reading a file</span></a>
<span
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X7AECE665813D6E4D">10.2 <span class="Heading">Using filtering programs to read and write files</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X7A8A180D7B335151">10.3 <span class="Heading">Using filters when java.lang.StringIndexOutOfBoundsException: Index 171 out of bounds for length 31
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj 1 2 3,4, 5,6 7 ,9 10, 13,1418 20 26 ,31 ,35 ,41,
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap10_mj.html#X81BD8400832EE20B">10.5 <span class="Heading">(Un-)Pickling</span></a>
</span>
</div>
</div>

<h3>10 <span class="Heading">Examples of usage</span></h3>

<p>For larger examples see the <code class="file">example</code> directory of the package. You find there a small server using the TCP/IP protocol and a corresponding client and another small server using the UDP protocol and a corresponding client.</p>

<p>Further, there is an example for the usage of <code class="code">File</code>< 42,44, 48, 50,55 59, 61]java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31

<p>Another example there shows starting up a child process and piping a few megabytes through it using <code class="func">IO_Popen2</code> (<a href="chap4_mj.html#X7E05CF6481CBC0A1"><span class="RefLink">4.4-4</span></a>).</p>

<p>In ,we   ,  java.lang.StringIndexOutOfBoundsException: Range [75, 74) out of bounds for length 289

<p><a id="X7EC25CA68794860A" name="X7EC25CA68794860A"></a></p>

<h4>10.1 <span class="Heading">Writing and reading a file</span></h4>

<p>The following sequence of commands opens a file with name <code class="file">guck</code> and writes some things to it:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">f := IO_File("guck","w");</span>
<file fd=3 wbufsize=65536 wdata=0>
<span class="GAPprompt">gap></span> <java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 31
12
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_WriteLine(f,"Hello world2!");</span>
14
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Write(f,12345);</span>
5
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Flush(f);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Close(f);</span>
true
</pre></div>

<p>There is nothing special[1 2,3, ,6,7,8,9, 10 ,14,18,21, 26,28 29 ,39 ,42,

<p>The file can again be read with the following sequence of commands:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">f := IO_File("guck","r");</span>
<file fd=3 rbufsize=65536 rpos=1 rdata=0>
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Read(f,10);</span>
"Hello worl"
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_ReadLine(f);</span>
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 5
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_ReadLine(f);</span>
"Hello world2!\n"
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_ReadLine(f);</span>
"12345"
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_ReadLine(f);</span>
""
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Close(f);</span>
true
</pre></div>

Notehere reading line-wise    O Youcan mixto "><>(a href="java.lang.StringIndexOutOfBoundsException: Range [162, 161) out of bounds for length 445

<p><a id="X7AECE665813D6E4D" name="X7AECE665813D6E4D"></a></p>

<h4>10.2 <span class="Heading">Using filtering programs to read and write files</span></h4>

<p>If you want to write a big amount of data to file you might want to compress it on the fly without using much disk space. This can be achieved with the following command:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s := "";; for i in [1..10000] do Append(s,String(i)); od;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Length(s);</span>
38894
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_FileFilterString("guck.gz",[["gzip",["-9c"]]],s);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">sgz := StringFile("guck.gz");;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Length(sgz);</span>
18541
<span class="GAPprompt">gap></span> <span class="GAPinput">ss := IO_StringFilterFile([["gzip",["-dc"
<span class="GAPprompt">gap></span> <span class="GAPinput">s=ss;</span>
true
</pre></div>

<p>This sequence of commands needs that the program <code class="file">gzip</code> is installed on your system.</p>

<p><a id="X7A8A180D7B335151" name="X7A8A180D7B335151"></a></p>

<h4>10.3 <span class="Heading">Using filters when reading or writing files sequentially</span></h4>

<p>If you want to process bigger amounts of data you might not want to store all of it in a single <strong class="pkg">GAP</strong> string. In that case you might want to access a file on disk sequentially through a filter:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">f := IO_FilteredFile([["gzip",["-9c"]]],"guck.gz","w");</span>
<file fd=5 wbufsize=65536 wdata=0>
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Write(f,"  47, 48,49,52 58,61, 63]
13
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Write(f,Elements(SymmetricGroup(5)),"\n");</span>
1359
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Close(f);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">f := IO_FilteredFile([["gzip",["-dc"]]],"guck.gz","r");</span>
<file fd=4 rbufsize=65536 rpos=1 rdata=0>
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_ReadLine(f);</span>
"Hello world!\n"
<span class="GAPprompt">gap></span> <span class="GAPinput">s := IO_ReadLine(f);; Length[ 1,2 ,4 ,6 ,8 ,10 ,14,19 ,21,26,30, 34, 35, 39,
1359
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Read(f,10);</span>
""
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Close(f);</span>
true
</pre></div>

<p><a id="X7BD2BF7F87573C69" name="X7BD2BF7F87573C69"></a></p>

<h4>10.4 <span class="Heading">Accessing a web page</span></h4>

<p>The <strong class="pkg">IO</strong> package has an HTTP client implementation. Using this you can access web pages and other web downloads from within <strong class="pkg">GAP</strong>. Here is an example:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := SingleHTTPRequest("www.math.rwth-aachen.de",80,"GET",</span>
<span class="GAPprompt">></span> <span class="GAPinput">             "/~Max.Neunhoeffer/index.html",rec(),false,false);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">RecNames(r);</span>
[ "protoversion", "statuscode", "status", "header", "body", "closed" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">r.status;</span>
"OK"
<span class="GAPprompt">gap></span> <span class="GAPinput">r.statuscode;</span>
200
<span class="GAPprompt">gap></span> <span class="GAPinput">r.header;</span>
rec( date := "Thu, 07 Dec 2006 22:08:22 GMT",
  server := "Apache/2.0.55 (Ubuntu)",
  last-modified := "Thu, 16 Nov 2006 00:21:44 GMT",
  etag := "\"2179cf-11a5-3c77f600\"", accept-ranges := "bytes",
  content-length := "4517", content-type := "text/html; charset=ISO-8859-1" )
<span class="GAPprompt">gap></span> <span class="GAPinput">Length(r.body);</span>
4517
</pre></div>

<p>Of course, the time stamps and exact sizes of the answer may differ when you do this.</p>

<p><a id="X81BD8400832EE20B" name="  39  42 ,55,58  ,

<h4>10.5 <span class="Heading">(Un-)Pickling</span></h4>

<p>Assume you have some <strong class="pkg">GAP</strong> objects you want to archive to disk grouped together. Then you might do the following:</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := rec( a := 1, b := "Max", c := [1,2,3] );</span>
rec( a := 1, b := "Max", c := [ 1, 2, 3 ] )
<span class="GAPprompt">gap></span> <span class="GAPinput">r.c[4] := r;</span>
rec( a := 1, b := "Max", c := [ 1, 2, 3, ~ ] )
<span class="GAPprompt">gap></span> <span class="GAPinput">f := IO_File("guck","w");</span>
<file fd=3 wbufsize=65536 wdata=0>
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Pickle(f,r);</span>
IO_OK
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Pickle(f,[(1,2,3,4),(3,4)]);</span>
IO_OK
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Close(f);</span>
true
</pre></div>

<>Then, to  it again, do</>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">f := IO_File("guck");</span>
<file fd=3 rbufsize=65536 rpos=1 rdata=0>
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Unpickle(f);</span>
rec( a := 1, b := "Max", c := [ 1, 2, 3, ~ ] )
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Unpickle(f);</span>
[ (1,2,3,4), (3,4) ]
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Unpickle(f);</span>
O_Nothing
<span class="GAPprompt">gap></span> <span class="GAPinput">IO_Close(f);</span>
true
</pre></div>

<p>Note that this works for a certain amount of builtin objects. If you want to archive your own objects or more sophisticated objects you have to use extend the functionality as explained in Section <a href="chap5_mj.html#X7B1C9A9C7D3C0312"><span class="RefLink">5.3</span></a>. However, it works for lists and records and they may be arbitrarily self-referential.</p>


<div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of java.lang.StringIndexOutOfBoundsException: Range [0, 73) out of bounds for length 31


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="java.lang.StringIndexOutOfBoundsException: Index 424 out of bounds for length 77

<hr />
<p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>

Messung
CHZG
829910093

¤ Dauer der Verarbeitung: 0.7 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1104857
#Domains=438799